I have a project with C++ code (JNI) and lots of build variants and combinations. These are used to implement different brandings / flavors of the app (i.e. colors, styles, icons, ...).
For example there could be build variants for n customers :
customerNDebug
customerNDebugproguard
customerNRelease
. Anyway, the C/C++ layer is the same for each product flavor.
Normally CMake in Android Studio compiles C code for every build variant. This makes sense if you have build variants like "debug
" and "release
" where the resulting code actually differs. However, for the build variants I have, the compiled output is always the same.
At the moment the compilation of C/C++ code is done using an external tool in our project and I want to compile using CMake in Android Studio only for proper IDE support of C/C++ code. So for me a single build would suffice.
Is it possible to tell Android Studio to build C/C++ code only once, no matter the build variants and flavors?
By default, Android Studio IDE together with CMake and Gradle will generate a series of native build tasks named with externalNative<BuildVariant>Build
according to your build types and flavours. If you want to twist this behaviour, some workaround is as below:
shared-native
. For this solution, you need to consider below points:
.so
files into a proper location that other projects can see and link with. debug
and release
build types for this shared-native
module project to avoid too many times of re-build. Or you can simply to let your other projects depends on the release type so that it will be built only ONCE. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With