强制 Android Studio 编译 ARM64 版本的外部库

Force Android Studio to compile ARM64 versions of external libraries

我正在尝试使用此处解释的方法将 CrossWalk 嵌入原生 android: embed crosswalk in android studio

我遇到的问题是 androidstudio 没有为 ARM64 构建所需的库,即使这些库位于 Maven 存储库中。

这是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "my.app.id"
        minSdkVersion 19
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven {
        url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
    }
    flatDir{
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'org.xwalk:xwalk_core_library:22.52.561.4'
    compile (name: 'wikitudesdk', ext:'aar')
    testCompile 'junit:junit:4.12'
}

有没有办法明确地告诉 android studio 编译这些库?

查看 Crosswalk AAR 版本 部分 https://crosswalk-project.org/documentation/android/embedding_crosswalk/crosswalk_aar.html:

  1. Support different CPU architectures with each APK (such as for ARM, x86).

    A product flavor defines a customized version of the application build by the project. We can have different flavors which generate apk for each architecture.

    android {
      ...
      productFlavors {
        armv7 {
          ndk {
            abiFilters "armeabi-v7a", ""
          }
        }
        x86 {
          ndk {
            abiFilters "x86", ""
          }
        }
      }
    }
    

    Get the version code from the manifest. Add an extra digit to the end of the version code which implicity specifies the architecture. The x86 final digit is 4, arm is 2.

    versionCode manifest.versionCode + 4
    
  2. Build your project with Gradle, the following commands will build the corresponding arch apk in build/apk directory.

    $ gradle assemblex86
    $ gradle assemblearmv7
    

    Use $ gradle build to build both arm and x86 APKs at once.

OpenCV 为 arm64 使用了这些魔法字符串:digit 3 和 abiFilter arm64-v8a (reference).

好的,我终于在这里找到了解决方案: diego.org

基本上,如果您需要 ARM64 库,您首先需要自己下载正确的库:

curl -O https://download.01.org/crosswalk/releases/crosswalk/android/maven2/org/xwalk/xwalk_core_library/22.52.561.4/xwalk_core_library-22.52.561.4-arm64.aar

然后安装到本地maven仓库:

mvn install:install-file -DgroupId=org.xwalk -DartifactId=xwalk_core_library \
  -Dversion=22.52.561.4-arm64 -Dpackaging=aar  \
  -Dfile=xwalk_core_library-22.52.561.4-arm64.aar \
  -DgeneratePom=true

并更新您的构建 gradle 以便存储库指向您本地的 Maven 存储库:

repositories {
    mavenLocal()
}

并且你编译了正确的库:

compile 'org.xwalk:xwalk_core_library:22.52.561.4-arm64'

希望对以后的人有所帮助。