如何为某些构建变体禁用Android NDK构建 [英] How to disable Android NDK build for some build variant
问题描述
我正在使用Android Studio 2.2,并已设置Gradle通过CMake使用NDK构建c/c ++源.
I am using Android Studio 2.2 and have setup Gradle to build c/c++ sources with NDK via CMake.
现在,我想为buildType"debug"禁用NDK构建.对于buildType"release",我想保留它.
Now I would like to disable NDK build for buildType "debug". For buildType "release" I would like to keep it.
目标是使NDK源代码在构建服务器上编译(使用发行版"),但对开发人员禁用它(使用调试").
The goal is to make NDK sources compile on the build server (using "release") but disable it for developers (using "debug").
这是当前正在使用的build.gradle文件:
This is the build.gradle file currently in use:
android {
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
defaultConfig {
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang"
cppFlags "-std=c++14"
}
}
ndk {
abiFilters 'armeabi-v7a', 'x86'
}
}
buildTypes {
release {
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang"
cppFlags "-std=c++14"
}
}
ndk {
abiFilters 'armeabi-v7a'
}
}
}
}
-
如何为defaultConfig或buildType"debug"禁用NDK构建(externalNativeBuild)?
How can I disable NDK build (externalNativeBuild) for defaultConfig or buildType "debug"?
其他开发人员不会安装NDK(local.properties 没有 ndk.dir = PATH_TO_NDK).可以配置吗?
Other developers won't have NDK installed (local.properties without ndk.dir=PATH_TO_NDK). Is this possible to configure?
预先感谢
此externalNativeBuild必须配置为"com.android.library"模块,而不是"com.android.application"模块.
This externalNativeBuild must be configured with a 'com.android.library'-module, not a 'com.android.application'-module.
推荐答案
这是我解决的方法.
以此为目标,Gradle构建适用于安装和未安装NDK (以及在构建服务器上)的开发人员.
This way Gradle build works for developers with and without NDK installed (and on the build server), which was the goal.
/*
* As soon as Gradle is linked to the externalNativeBuild (cmake / ndkBuild) with a path to
* CMakeLists.txt / Android.mk, the ndk.dir from local.properties file or the ANDROID_NDK_HOME
* environment variable needs to be set, otherwise gradle fails.
* E.g.:
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
*/
// Only enable externalNativeBuild on machines with NDK installed -> valid ndkDir
def ndkDir = project.android.ndkDirectory;
if (ndkDir != null && !ndkDir.toString().isEmpty()) {
externalNativeBuild.cmake.path = "CMakeLists.txt"
}
这篇关于如何为某些构建变体禁用Android NDK构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!