在构建Android应用时禁用CMake目标 [英] Disabling a CMake target when building Android app
问题描述
我有一个Android应用程序,该应用程序使用通过CMake构建的C ++本机代码.在项目的CMakeLists中,使用 add_subdirectory()
添加了一个库.该库有许多目标,其中有些目标无法在Android平台上编译(它们会在Android上产生编译错误).但是,我的Android应用程序没有针对任何这些目标进行链接,因此根本不需要构建这些目标.但是Android Studio仍会尝试构建它们.
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.
我的问题是,是否有可能在Android Studio中以某种方式禁用这些目标.我可以告诉Android Studio不要建立这些目标吗?
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?
推荐答案
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"
}
}
}
}
或者,您可以修改库的CMakeLists.txt,以将有问题的目标排除在自动构建之外.
Alternatively you could hack the library's CMakeLists.txt to exclude the problematic targets from building automatically.
这篇关于在构建Android应用时禁用CMake目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!