Disabling a CMake target when building Android app

ε祈祈猫儿з 提交于 2021-02-10 18:42:55

问题


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

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