问题
I have an Android app that uses C++ native code which is built using CMake. In the project's CMakeLists a library is added using add_subdirectory()
. This library has many targets, some of which do not compile for Android platform (they produce compile errors on Android). However my Android app does not link against any of those targets, so they do not need to be built at all. But Android Studio tries to build them anyway.
My question is if it is possible to somehow disable those targets in Android Studio. Can I tell Android Studio to not build those targets?
回答1:
Google has thought of that: you can select which targets to build.
The example below is a minimal version of the linked one; it only builds libexample-one
:
android {
defaultConfig {
externalNativeBuild {
cmake {
// Note that Gradle packages only shared libraries into your APK.
targets "libexample-one"
}
}
}
}
Alternatively you could hack the library's CMakeLists.txt to exclude the problematic targets from building automatically.
来源:https://stackoverflow.com/questions/57007783/disabling-a-cmake-target-when-building-android-app