androidandroid-ndkandroid-gradle-pluginandroid-build

Support to 64-bit gives error on adding ndk.abiFilters in build.gradle


Most of the android developers must have got the message from Google to update the apps to support 64-bit architecture by Aug 2019. The detailed instructions are given here: Ensure that your app supports 64-bit devices

In my app, I found that the 32-bit libs are used and therefore I have to update the app to support 64-bit architecture. As suggested in the guide above, I added the following in build.gradle file:

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

However, after that, I get following error in building the app:

Error:(35, 0) Could not find method armeabi-v7a() for arguments [arm64-v8a] on DefaultConfig_Decorated{name=main, dimension=null, minSdkVersion=DefaultApiVersion{mApiLevel=16, mCodename='null'}, targetSdkVersion=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} of type com.android.build.gradle.internal.dsl.DefaultConfig.

Has anybody already tried updating the app to 64-bit? Any idea, how to fix this issue?


Solution

  • It can be done by updating the 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'
    }
    

    or

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

    I have tested this on android-native and react-native app. build was successful and app was working.