Skip to content Skip to sidebar Skip to footer

Android Studio Cmake Build Once For All Build Variants

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,

Solution 1:

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:

  1. Create an Android Studio module project which only builds your native code, e.g. shared-native.
  2. Let the rest of your modules dependent on this project.

For this solution, you need to consider below points:

  1. Put your .so files into a proper location that other projects can see and link with.
  2. You can only include 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.

Post a Comment for "Android Studio Cmake Build Once For All Build Variants"