Android Studio CMake build once for all build variants

不打扰是莪最后的温柔 提交于 2019-12-19 10:24:51

问题


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?


回答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.


来源:https://stackoverflow.com/questions/53847619/android-studio-cmake-build-once-for-all-build-variants

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!