首页 > 解决方案 > 如何为 armv8 编译本机库?

问题描述

我正在为四种架构 x86、x86_64、armeabi-v7a 和 arm64-v8a 编译拆分 apk。该应用程序运行良好,并且可以在大多数设备上正常加载本机库。但在某些设备上,出现无法在 armv8 文件夹或 arm 文件夹中找到 mylibrary.so .in 的错误。这是我生成拆分 apk 并生成不满意链接错误的代码

splits {
        // Configures multiple APKs based on ABI.
        abi {
            // Enables building multiple APKs per ABI.
            enable true


            // By default all ABIs are included, so use reset() and include to specify that we only
            // want APKs for x86, armeabi-v7a, and mips.
            reset()

            // Specifies a list of ABIs that Gradle should create APKs for.
            include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"

            // Specifies that we want to also generate a universal APK that includes all ABIs.
            universalApk false
        }
    }



    def abiCodes = ['x86':0, 'x86_64':1, 'armeabi-v7a':2, 'arm64-v8a':3]
    android.applicationVariants.all { variant ->
        // Assigns a different version code for each output APK.
        variant.outputs.each {
            output ->
                def abiName = output.getFilter(OutputFile.ABI)
                output.versionCodeOverride = abiCodes.get(abiName, 0) + variant.versionCode
        }
    }

当我分析 apk 时,我成功地在 libs 文件夹和所有其他 apk 的 libs 文件夹中的 arm64-v8a apk 中获得所需的本机库。

标签: androidandroid-studiocmakeandroid-ndk

解决方案


推荐阅读