3

I have an android application supporting 4 different architectures namely armeabi-v7a, arm64-v8a, x86 and x86_64. I don't want each of these architectures to be built for every Android built. I want to pass the architecture information as an argument via the gradlew command so that the builds of remaining architectures is skipped. I am aware that -DANDROID_ABI flag passed as an argument to cmake would do the trick but not sure how to pass it as an argument via the gradlew command?

defaultConfig {
    minSdkVersion 21
    targetSdkVersion 26

    externalNativeBuild {
        cmake {
            cppFlags "-frtti -fexceptions"
            arguments "-DANDROID_ABI=<<requested arch to built>>"
        }
    }
}

In other words, How can this information be passed from the gradlew command to the cmake?

shizhen
  • 12,251
  • 9
  • 52
  • 88
Varun Bhatia
  • 4,326
  • 32
  • 46

2 Answers2

4

The trick can be like below:

android {   
    ...
    defaultConfig {
        externalNativeBuild {
            cmake {
                ...

                if (project.hasProperty("armeabi-v7a")) {
                    abiFilters 'armeabi-v7a'
                } else if (project.hasProperty("arm64-v8a")) {
                    abiFilters 'arm64-v8a'
                } else if (project.hasProperty("x86")) {
                    abiFilters 'x86'
                } else if (project.hasProperty("x86_64")) {
                    abiFilters 'x86_64'
                } else {
                    abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
                }
                ...
            }
        }
    }
}

From command line, you can do as below, e.g. to only build abi armeabi-v7a

./gradlew externalNativeBuild -Parmeabi-v7a
shizhen
  • 12,251
  • 9
  • 52
  • 88
-1
https://developer.android.com/studio/build/gradle-tips#configure-separate-apks-per-abi

You can create multiple apks using same code.

android {
  ...
  splits {

    // Configures multiple APKs based on ABI.
    abi {

      // Enables building multiple APKs.
      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", "armeabi-v7a", "mips"

      // Specify that we want to also generate a universal APK that includes all ABIs.
      universalApk true
    }
  }
}
Ranjan Kumar
  • 1,164
  • 7
  • 12