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屬性來指明靜態庫名。