Felix.D
Felix.D

Reputation: 724

How to override defaultConfig abiFilters in buildTypes

abiFilters is set in android build.gradle defaultConfig block.

I'd like to exclude x86 from release buildType, but can't find an easy way to do it

Here is the build.gradle:

defaultConfig {
    ndk {
        abiFilters "armeabi", "x86"
        moduleName "cipher_v1"
        cFlags "-DRELEASE=1"
        if (rootProject.ext.has("testCrack")) {
            cFlags += " -DTEST_CRACK"
        }
        if (project.ext.has("authKey") && project.ext.has("androidId")) {
            cFlags += "-DAUTH_KEY=\\\"" + project.ext.authKey + "\\\""
            "-DANDROID_ID=\\\"" + project.ext.androidId + "\\\""
        }
    }
}

buildTypes {
   release {
        ndk {
            abiFilters "armeabi"
        }
    }
}

Here is what I get:

unzip -l base-release.aar|grep cipher
17752  02-01-1980 00:00   jni/armeabi/libcipher_v1.so
17640  02-01-1980 00:00   jni/x86/libcipher_v1.so

Here is what I really want:

unzip -l base-release.aar|grep cipher
17752  02-01-1980 00:00   jni/armeabi/libcipher_v1.so

I'd like to keep a full abiFilters in the defautlConfig block

And specify ones in certain buildType


EDIT 1:

Yes, removing the defaultConfig and setting abiFilters in both debug & release block would work. But my question is how to utilize the defaultConfig

Upvotes: 6

Views: 3007

Answers (3)

Felix.D
Felix.D

Reputation: 724

Thanks to Martin, I found a workable solution from this:

when defaultConfig would only have armeabi configured and build-type debug would then add x86, this might work out

I realize that adding wanted abi to debug is a workaround for removing unwanted abi for release

Works For Me

defaultConfig {
    ndk {
      //abiFilters "armeabi", "x86"
        abiFilters "armeabi"
    }
}

buildTypes {
    debug {
        ndk {
          //abiFilters "armeabi", "x86"
            abiFilters "x86"
        }
    }
    release {
        //ndk {
        //    abiFilters "armeabi"
        //}
   }
}

Upvotes: 2

shizhen
shizhen

Reputation: 12583

Feeding a command line option, e.g. "no_x86"

  1. Add below to your app/build.gradle

    defaultConfig {
        ndk {
    
            ...
            if (project.hasProperty("no_x86")) {
                abiFilters "armeabi"
            } else {
                abiFilters "armeabi", "x86"
            }
    
            ...
        }
    }
    
  2. Use below command to generate the APKs without x86 ABI by feeding option no_x86 to the command.

    ./gradlew assemble -Pno_x86
    

    but don't feed option no_x86 to the command if you want to build APKs with x86 abi. As the defaultConfig is to keep a full abiFilters per your requirement.

    For certain buildType, you can invoke the corresponding build command by feeding or not feeding the -Pno_x86 property. E.g. ./gradlew assembleRelease -Pno_x86

Reference: https://stackoverflow.com/a/52980193/8034839

Upvotes: 6

Martin Zeitler
Martin Zeitler

Reputation: 76669

android {
    buildTypes {
        debug {
            ndk {
                abiFilters "armeabi", "x86"
            }
        }
        release {
            ndk {
                abiFilters "armeabi"
            }
        }
    }
}

productFlavors also would support dimension abi.

Upvotes: 2

Related Questions