Issue
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?
Solution
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
Answered By - shizhen