首页 文章

React-Native Android,仅适用于armeabi架构

提问于
浏览
6

注意:我正在提供这些库,我不能为其他架构制作其他库 .

我目前正在移植一个Android应用程序,以反应本地使用本机库,但我只有 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,并且缺少一些库 .

这是我的反应原生的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"

2 回答

  • 3

    您必须在 application.mk 中指定所需的架构类型 .

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

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

  • 1

    如果您使用Experimental Gradle Build

    将此添加到build.gradle

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

    其他

    APP_ABI:=all in Application.mk
    

    More

相关问题