【问题标题】:React-Native + Android, only build for armeabi architectureReact-Native + Android,只为 armeabi 架构构建
【发布时间】: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"

【问题讨论】:

标签: android android-ndk react-native react-native-android


【解决方案1】:

你必须在application.mk中指定你想要什么样的架构。

要支持所有架构,请在 application.mk 文件中使用此属性 APP_ABI := all

这里是文档https://developer.android.com/ndk/guides/application_mk.html

【讨论】:

    【解决方案2】:

    如果您使用实验性 Gradle 构建

    将此添加到 build.gradle

    abiFilters.addAll([
                "armeabi-v7a",
                "arm64-v8a",
                "x86",
                "x86_64"
        ])
    

    其他

    APP_ABI:=all in Application.mk
    

    More

    【讨论】:

    • 试过但没有成功。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    • 2019-03-21
    • 2017-06-26
    • 1970-01-01
    • 1970-01-01
    • 2022-07-26
    • 1970-01-01
    相关资源
    最近更新 更多