Google关于Android Gradle DSL的官方文档:
Android Gradle DSL
一、cmake
下面由两个cmake语句,但其类型不同,所以其属性不同
1、CmakeOptions类型的cmake
路径:
(AppExtension) android->
(ExternalNativeBuild) externalNativeBuild ->
(CmakeOptions) cmake
android {
externalNativeBuild {
cmake {
buildStagingDirectory "./outputs/cmake"
path "CMakeLists.txt"
version "3.7.1"
}
}
}
AppExtension :The android extension for application plugins.
即,android{ 这里使用 }
Property | Description |
---|---|
buildStagingDirectory | Specifies the path to your external native build output directory. |
path | Specifies the relative path to your CMakeLists.txt build script. |
version | The version of CMake that the Android plugin should use when building your CMake project. |
2、ExternalNativeCmakeOptions类型的cmake
路径:
(AppExtension) android->
(DefaultConfig) defaultConfig->
(ExternalNativeBuildOptions) externalNativeBuild->
(ExternalNativeCmakeOptions) cmake
android {
defaultConfig {
externalNativeBuild {
cmake {
arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang"
cFlags "-D__STDC_FORMAT_MACROS"
cppFlags "-fexceptions", "-frtti"
targets "libexample-one"
}
}
}
}
Property | Description |
---|---|
abiFilters | Specifies the Application Binary Interfaces (ABI) that Gradle should build outputs for. The ABIs that Gradle packages into your APK are determined by NdkOptions.abiFilter() |
arguments | Specifies arguments for CMake. |
cFlags | Specifies flags for the C compiler. |
cppFlags | Specifies flags for the C++ compiler. |
targets | Specifies the library and executable targets from your CMake project that Gradle should build. If you don’t configure this property, Gradle builds all executables and shared object libraries that you define in your ndk-build project. However, by default, Gradle packages only the shared libraries in your APK. |
通过targets属性的描述可知,默认只打包“动态库文件”,即.so文件。
如果希望生成“静态库文件”,即.a文件,则需要加上targets属性来指明静态库名。