首页 > 解决方案 > 对 64 位的支持会在 build.gradle 中添加 ndk.abiFilters 时出错

问题描述

大多数安卓开发者一定已经收到谷歌的消息,要求在 2019 年 8 月之前更新应用程序以支持 64 位架构。详细说明如下: 确保您的应用程序支持 64 位设备

在我的应用程序中,我发现使用了 32 位库,因此我必须更新应用程序以支持 64 位架构。正如上面指南中所建议的,我在build.gradle文件中添加了以下内容:

ndk.abiFilters = 'armeabi-v7a' 'arm64-v8a' 'x86' 'x86_64'

但是,在那之后,我在构建应用程序时遇到以下错误:

错误:(35, 0) 在 DefaultConfig_Decorated{name=main, dimension=null, minSdkVersion=DefaultApiVersion{mApiLevel=16, mCodename='null'}, targetSdkVersion 上找不到参数 [arm64-v8a] 的方法 armeabi-v7a() =DefaultApiVersion{mApiLevel=28, mCodename='null'}, renderscriptTargetApi=null, renderscriptSupportModeEnabled=null, renderscriptSupportModeBlasEnabled=null, renderscriptNdkModeEnabled=null, versionCode=3, versionName=1.2, applicationId=, testApplicationId=null, testInstrumentationRunner=null, testInstrumentationRunnerArguments ={},testHandleProfiling=null,testFunctionalTest=null,signingConfig=null,resConfig=null,mBuildConfigFields={},mResValues={},mProguardFiles=[],mConsumerProguardFiles=[],mManifestPlaceholders={},mWearAppUnbundled=null}输入 com.android.build.gradle.internal.dsl。默认配置。

是否有人已经尝试将应用程序更新为 64 位?任何想法,如何解决这个问题?

标签: androidandroid-ndkandroid-gradle-pluginandroid-build

解决方案


可以通过更新 build gradle defaultConfig 来完成

defaultConfig {
    applicationId "my.test.64bitapp"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 42
    versionName "1.0.2"
    multiDexEnabled true
    vectorDrawables.useSupportLibrary = true
    ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86' ,'x86_64'
}

或者

defaultConfig {
    applicationId "com.swypmedia"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 2
    versionName "2.0.2"
    ndk {
        abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86' ,'x86_64'
    }
}

我已经在 android-native 和 react-native 应用程序上对此进行了测试。构建成功并且应用程序正在运行。


推荐阅读