【发布时间】:2017-01-28 04:45:58
【问题描述】:
注意:我得到了这些库,我无法为其他架构制作其他库。
我目前正在将一个 Android 应用程序移植到使用原生库的 react-native,但我只有 armeabi 可用。到目前为止,原始项目没有问题,因为armeabi is supported by all the x86/x86_64/armeabi-v7a/arm64-v8a devices。
然后,当我从 react-native 生成一个新项目并包含那些 armeabi 文件时,在运行 apk 时找不到一些库。当我解压缩由原始项目生成的 apk 时,我可以找到包含所有库的文件夹:lib/armeabi,所以没问题。现在,当我解压缩由 react-native 生成的 apk 时,我有 2 个文件夹:lib/armeabi-v7a 和 lib/x86,并且缺少一些库。
这是我使用 react-native 的 gradle 配置:
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId "com.poc"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
veryVerbose {
}
}
signingConfigs {
releaseConfig {
}
buildTypes {
release {
debuggable true
jniDebuggable false
signingConfig signingConfigs.releaseConfig
}
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
// Player library
veryVerboseCompile fileTree(dir: 'veryVerboseLibs', include: ['*.jar'])
debugCompile fileTree(dir: 'releaseLibs', include: ['*.jar'])
releaseCompile fileTree(dir: 'releaseLibs', include: ['*.jar'])
// Google
compile "com.android.support:appcompat-v7:23.0.1"
// Square
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
// From node_modules
compile "com.facebook.react:react-native:+"
}
似乎 react-native 会自动生成一些有关架构的配置,对我来说有点新,我需要告诉 gradle 为 armeabi 构建并将所有这些库包含到我最终 apk 中的 lib/armeabi 文件夹中。
基本上我从 logcat 得到的并运行 apk 是:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.siminntvpoc-2/base.apk"],nativeLibraryDirectories=[/data/app/com.siminntvpoc-2/lib/x86, /data/app/com.siminntvpoc-2/base.apk!/lib/x86, /vendor/lib, /system/lib]]] couldn't find "libViewRightWebClient.so"
【问题讨论】:
-
所以您的应用程序构建良好?您必须仅在模拟器中而不是在实际设备中遇到此错误。是这样吗?
-
还要考虑到反应原生 doesn't support 3rd party 64bit libraries and cannot mix+match 32 and 64bit 库(截至 2017 年 8 月)
标签: android android-ndk react-native react-native-android