I have an Android Gradle + CMake (NDK) project with several options. C ++ source files / libraries in subprojects are unnecessarily rebuilt after switching to a flavor that was not previously built. Which is kindly expected, giving this folder a special flavor and does not exist when created for the first time:
./app/.externalNativeBuild/cmake/prodDebug/armeabi/libs/mylib/libmylib.a ./app/.externalNativeBuild/cmake/devDebug/armeabi/libs/mylib/libmylib.a
But I have many tastes and large libraries for the assembly and I do not want to rebuild C ++ libraries that are tasteless - there are libraries that should be the same for every taste when building. I tried to fix this by specifying a different output directory so that it was tasteless:
add_subdirectory("libs/mylib" "${CMAKE_CURRENT_SOURCE_DIR}/libs/mylib/output")
Each taste now has the same output directory of the mylib library, but this time the library is constantly being rebuilt when switching flavors. When using regular CMake without Gradle, everything works as expected. Is there a way to fix unnecessary rebuilds when compiling from Android Studio / Gradle?
EDIT1: Btw, rebuilds are executed even if tastes do not indicate any C ++ flags, etc. - in fact, they are the same for another application / version name:
dev { applicationIdSuffix ".dev" versionNameSuffix "-dev" } prod { applicationIdSuffix ".prod" versionNameSuffix "-prod" }
EDIT2: There is also another recovery problem there. When you change any CMakeLists.txt (also a subproject), it starts a whole tree rebuild - all parent projects, subprojects (even unrelated ones) are rebuilt. This is currently a trial version for using Gradle / Android Studio to create NDK projects.
source share