Stay organized with collections
Save and categorize content based on your preferences.
ExternalNativeBuildFlags
@Incubating interface ExternalNativeBuildFlags
DSL object for per-variant CMake and ndk-build configurations, such as toolchain arguments and compiler flags.
android {
// Similar to other properties in the defaultConfig block, you can override
// these properties for each product flavor you configure.
defaultConfig {
// This block is different from the one you use to link Gradle
// to your CMake or ndk-build script.
externalNativeBuild {
// For ndk-build, instead use the ndkBuild block.
cmake {
// Passes optional arguments to CMake.
arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang"
// Sets a flag to enable format macro constants for the C compiler.
cFlags "-D__STDC_FORMAT_MACROS"
// Sets optional flags for the C++ compiler.
cppFlags "-fexceptions", "-frtti"
// Specifies the library and executable targets from your CMake project
// that Gradle should build.
targets "libexample-one", "my-executible-demo"
}
}
}
}
To enable external native builds and set the path to your CMake or ndk-build script, use android.externalNativeBuild
.
Summary
Public functions |
Unit |
Encapsulates per-variant CMake configurations, such as compiler flags and toolchain arguments.
|
Unit |
Encapsulates per-variant ndk-build configurations, such as compiler flags and toolchain arguments.
|
Public properties |
CmakeFlags |
Encapsulates per-variant CMake configurations, such as compiler flags and toolchain arguments.
|
MutableMap<String, Any> |
Additional per-variant experimental properties for C and C++.
|
NdkBuildFlags |
Encapsulates per-variant ndk-build configurations, such as compiler flags and toolchain arguments.
|
Public functions
Public properties
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# ExternalNativeBuildFlags\n========================\n\n\n```\n@Incubating interface ExternalNativeBuildFlags\n```\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nDSL object for per-variant CMake and ndk-build configurations, such as toolchain arguments and compiler flags. \n\n```gdscript\nandroid {\n // Similar to other properties in the defaultConfig block, you can override\n // these properties for each product flavor you configure.\n defaultConfig {\n // This block is different from the one you use to link Gradle\n // to your CMake or ndk-build script.\n externalNativeBuild {\n // For ndk-build, instead use the ndkBuild block.\n cmake {\n // Passes optional arguments to CMake.\n arguments \"-DANDROID_ARM_NEON=TRUE\", \"-DANDROID_TOOLCHAIN=clang\"\n\n // Sets a flag to enable format macro constants for the C compiler.\n cFlags \"-D__STDC_FORMAT_MACROS\"\n\n // Sets optional flags for the C++ compiler.\n cppFlags \"-fexceptions\", \"-frtti\"\n\n // Specifies the library and executable targets from your CMake project\n // that Gradle should build.\n targets \"libexample-one\", \"my-executible-demo\"\n }\n }\n }\n}\n```\n\nTo enable external native builds and set the path to your CMake or ndk-build script, use [android.externalNativeBuild](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/ExternalNativeBuild).\n\nSummary\n-------\n\n| ### Public functions ||\n|------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [cmake](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/ExternalNativeBuildFlags#cmake(kotlin.Function1))`(action: @`[ExtensionFunctionType](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html)` `[CmakeFlags](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/CmakeFlags)`.() `-\u003e` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Encapsulates per-variant CMake configurations, such as compiler flags and toolchain arguments. |\n| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [ndkBuild](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/ExternalNativeBuildFlags#ndkBuild(kotlin.Function1))`(action: @`[ExtensionFunctionType](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-extension-function-type/index.html)` `[NdkBuildFlags](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/NdkBuildFlags)`.() `-\u003e` `[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)`)` Encapsulates per-variant ndk-build configurations, such as compiler flags and toolchain arguments. |\n\n| ### Public properties ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [CmakeFlags](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/CmakeFlags) | [cmake](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/ExternalNativeBuildFlags#cmake()) Encapsulates per-variant CMake configurations, such as compiler flags and toolchain arguments. |\n| [MutableMap](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-map/index.html)`\u003c`[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`\u003e` | [experimentalProperties](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/ExternalNativeBuildFlags#experimentalProperties()) Additional per-variant experimental properties for C and C++. |\n| [NdkBuildFlags](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/NdkBuildFlags) | [ndkBuild](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/ExternalNativeBuildFlags#ndkBuild()) Encapsulates per-variant ndk-build configurations, such as compiler flags and toolchain arguments. |\n\nPublic functions\n----------------\n\n### cmake\n\n```\nfun cmake(action: @ExtensionFunctionType CmakeFlags.() -\u003e Unit): Unit\n```\n\nEncapsulates per-variant CMake configurations, such as compiler flags and toolchain arguments.\n\nTo enable external native builds and set the path to your `CMakeLists.txt` script, use [android.externalNativeBuild.cmake.path](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/Cmake#path(kotlin.Any)). \n\n### ndkBuild\n\n```\nfun ndkBuild(action: @ExtensionFunctionType NdkBuildFlags.() -\u003e Unit): Unit\n```\n\nEncapsulates per-variant ndk-build configurations, such as compiler flags and toolchain arguments.\n\nTo enable external native builds and set the path to your `Android.mk` script, use [android.externalNativeBuild.ndkBuild.path](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/NdkBuild#path(kotlin.Any)).\n\nPublic properties\n-----------------\n\n### cmake\n\n```\nval cmake: CmakeFlags\n```\n\nEncapsulates per-variant CMake configurations, such as compiler flags and toolchain arguments.\n\nTo enable external native builds and set the path to your `CMakeLists.txt` script, use [android.externalNativeBuild.cmake.path](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/Cmake#path(kotlin.Any)). \n\n### experimentalProperties\n\n```\nval experimentalProperties: MutableMap\u003cString, Any\u003e\n```\n\nAdditional per-variant experimental properties for C and C++. \n\n### ndkBuild\n\n```\nval ndkBuild: NdkBuildFlags\n```\n\nEncapsulates per-variant ndk-build configurations, such as compiler flags and toolchain arguments.\n\nTo enable external native builds and set the path to your `Android.mk` script, use [android.externalNativeBuild.ndkBuild.path](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/NdkBuild#path(kotlin.Any))."]]