Stay organized with collections
Save and categorize content based on your preferences.
ExternalNativeBuildOptions
@Incubating interface ExternalNativeBuildOptions
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 methods
|
abstract Unit |
Encapsulates per-variant CMake configurations, such as compiler flags and toolchain
arguments.
|
abstract Unit |
Encapsulates per-variant ndk-build configurations, such as compiler flags and toolchain
arguments.
|
Properties
|
abstract ExternalNativeCmakeOptions |
Encapsulates per-variant CMake configurations, such as compiler flags and toolchain
arguments.
|
abstract ExternalNativeNdkBuildOptions |
Encapsulates per-variant ndk-build configurations, such as compiler flags and toolchain
arguments.
|
Public methods
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.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# ExternalNativeBuildOptions\n==========================\n\n```\n@Incubating interface ExternalNativeBuildOptions\n```\n\n|-----------------------------------------------------------|\n| [com.android.build.api.dsl.ExternalNativeBuildOptions](#) |\n\nDSL object for per-variant CMake and ndk-build configurations, such as toolchain arguments and\ncompiler 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\n[android.externalNativeBuild](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/ExternalNativeBuild).\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [cmake](#cmake(kotlin.Function1))`(`action:` `[ExternalNativeCmakeOptions](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/ExternalNativeCmakeOptions).()` `-\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| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [ndkBuild](#ndkBuild(kotlin.Function1))`(`action:` `[ExternalNativeNdkBuildOptions](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/ExternalNativeNdkBuildOptions).()` `-\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| ### Properties ||\n|-----------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [ExternalNativeCmakeOptions](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/ExternalNativeCmakeOptions) | [cmake](#cmake:com.android.build.api.dsl.ExternalNativeCmakeOptions) Encapsulates per-variant CMake configurations, such as compiler flags and toolchain arguments. |\n| abstract [ExternalNativeNdkBuildOptions](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/ExternalNativeNdkBuildOptions) | [ndkBuild](#ndkBuild:com.android.build.api.dsl.ExternalNativeNdkBuildOptions) Encapsulates per-variant ndk-build configurations, such as compiler flags and toolchain arguments. |\n\nPublic methods\n--------------\n\n### cmake\n\n```\nabstract fun cmake(action: ExternalNativeCmakeOptions.() -\u003e Unit): Unit\n```\n\nEncapsulates per-variant CMake configurations, such as compiler flags and toolchain\narguments.\n\nTo enable external native builds and set the path to your `CMakeLists.txt` script, use\n[android.externalNativeBuild.cmake.path](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/Cmake#path(kotlin.Any)). \n\n### ndkBuild\n\n```\nabstract fun ndkBuild(action: ExternalNativeNdkBuildOptions.() -\u003e Unit): Unit\n```\n\nEncapsulates per-variant ndk-build configurations, such as compiler flags and toolchain\narguments.\n\nTo enable external native builds and set the path to your `Android.mk` script, use\n[android.externalNativeBuild.ndkBuild.path](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/NdkBuild#path(kotlin.Any)).\n\nProperties\n----------\n\n### cmake\n\n```\nabstract val cmake: ExternalNativeCmakeOptions\n```\n\nEncapsulates per-variant CMake configurations, such as compiler flags and toolchain\narguments.\n\nTo enable external native builds and set the path to your `CMakeLists.txt` script, use\n[android.externalNativeBuild.cmake.path](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/Cmake#path(kotlin.Any)). \n\n### ndkBuild\n\n```\nabstract val ndkBuild: ExternalNativeNdkBuildOptions\n```\n\nEncapsulates per-variant ndk-build configurations, such as compiler flags and toolchain\narguments.\n\nTo enable external native builds and set the path to your `Android.mk` script, use\n[android.externalNativeBuild.ndkBuild.path](/reference/tools/gradle-api/7.1/com/android/build/api/dsl/NdkBuild#path(kotlin.Any))."]]