Stay organized with collections
Save and categorize content based on your preferences.
NdkBuild
@Incubating interface NdkBuild
DSL object for per-module ndk-build configurations, such as the path to your Android.mk
build script and external native build output directory.
To include ndk-build projects in your Gradle build, you need to use Android Studio 2.2 and
higher with Android plugin for Gradle 2.2.0 and higher. To learn more about Android Studio's
support for external native builds, read
Add C and C++ Code to Your Project
If you want to instead build your native libraries using CMake, see Cmake
Summary
Public methods
|
abstract Unit |
Specifies the path to your external native build output directory.
|
abstract Unit |
Specifies the relative path to your Android.
|
Properties
|
abstract File? |
Specifies the path to your external native build output directory.
|
abstract File? |
Specifies the relative path to your Android.
|
Public methods
buildStagingDirectory
abstract fun buildStagingDirectory(any: Any): Unit
Specifies the path to your external native build output directory.
If you do not specify a value for this property, the Android plugin uses the
<project_dir>/.cxx/
directory by default.
If you specify a path that does not exist, the Android plugin creates it for you.
Relative paths are relative to the build.gradle
file, as shown below:
android {
externalNativeBuild {
ndkBuild {
// Tells Gradle to put outputs from external native
// builds in the path specified below.
buildStagingDirectory "./outputs/ndk-build"
}
}
}
If you specify a path that's a subdirectory of your project's temporary build
directory, you get a build error. That's because files in this directory do not
persist through clean builds.
So, you should either keep using the default <project_dir>/.cxx/
directory or specify a path outside the temporary build directory.
path
abstract fun path(any: Any): Unit
Specifies the relative path to your Android.mk build script.
For example, if your ndk-build script is in the same folder as your project-level
build.gradle
file, you simply pass the following:
android {
externalNativeBuild {
ndkBuild {
// Tells Gradle to find the root ndk-build script in the same
// directory as the project's build.gradle file. Gradle requires this
// build script to add your ndk-build project as a build dependency and
// pull your native sources into your Android project.
path "Android.mk"
}
}
}
Properties
buildStagingDirectory
abstract var buildStagingDirectory: File?
Specifies the path to your external native build output directory.
If you do not specify a value for this property, the Android plugin uses the
<project_dir>/.cxx/
directory by default.
If you specify a path that does not exist, the Android plugin creates it for you.
Relative paths are relative to the build.gradle
file, as shown below:
android {
externalNativeBuild {
ndkBuild {
// Tells Gradle to put outputs from external native
// builds in the path specified below.
buildStagingDirectory "./outputs/ndk-build"
}
}
}
If you specify a path that's a subdirectory of your project's temporary build
directory, you get a build error. That's because files in this directory do not
persist through clean builds.
So, you should either keep using the default <project_dir>/.cxx/
directory or specify a path outside the temporary build directory.
path
abstract var path: File?
Specifies the relative path to your Android.mk build script.
For example, if your ndk-build script is in the same folder as your project-level
build.gradle
file, you simply pass the following:
android {
externalNativeBuild {
ndkBuild {
// Tells Gradle to find the root ndk-build script in the same
// directory as the project's build.gradle file. Gradle requires this
// build script to add your ndk-build project as a build dependency and
// pull your native sources into your Android project.
path "Android.mk"
}
}
}
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,["# NdkBuild\n========\n\n```\n@Incubating interface NdkBuild\n```\n\n|-----------------------------------------|\n| [com.android.build.api.dsl.NdkBuild](#) |\n\nDSL object for per-module ndk-build configurations, such as the path to your `Android.mk`\nbuild script and external native build output directory.\n\nTo include ndk-build projects in your Gradle build, you need to use Android Studio 2.2 and\nhigher with Android plugin for Gradle 2.2.0 and higher. To learn more about Android Studio's\nsupport for external native builds, read\n[Add C and C++ Code to Your Project](https://developer.android.com/studio/projects/add-native-code.html)\n\nIf you want to instead build your native libraries using CMake, see [Cmake](/reference/tools/gradle-api/7.0/com/android/build/api/dsl/Cmake)\n\nSummary\n-------\n\n| ### Public methods ||\n|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [buildStagingDirectory](#buildStagingDirectory(kotlin.Any))`(`any:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`)` Specifies the path to your external native build output directory. |\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [path](#path(kotlin.Any))`(`any:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`)` Specifies the relative path to your Android. |\n\n| ### Properties ||\n|------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|\n| abstract [File](http://docs.oracle.com/javase/8/docs/api/java/io/File.html)? | [buildStagingDirectory](#buildStagingDirectory:java.io.File) Specifies the path to your external native build output directory. |\n| abstract [File](http://docs.oracle.com/javase/8/docs/api/java/io/File.html)? | [path](#path:java.io.File) Specifies the relative path to your Android. |\n\nPublic methods\n--------------\n\n### buildStagingDirectory\n\nAdded in [API level 4.0.0](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun buildStagingDirectory(any: Any): Unit\n```\n\nSpecifies the path to your external native build output directory.\n\nIf you do not specify a value for this property, the Android plugin uses the\n`\u003cproject_dir\u003e/.cxx/` directory by default.\n\nIf you specify a path that does not exist, the Android plugin creates it for you.\nRelative paths are relative to the `build.gradle` file, as shown below: \n\n```text\nandroid {\n externalNativeBuild {\n ndkBuild {\n // Tells Gradle to put outputs from external native\n // builds in the path specified below.\n buildStagingDirectory \"./outputs/ndk-build\"\n }\n }\n}\n```\n\nIf you specify a path that's a subdirectory of your project's temporary `build`\ndirectory, you get a build error. That's because files in this directory do not\npersist through clean builds.\nSo, you should either keep using the default `\u003cproject_dir\u003e/.cxx/`\ndirectory or specify a path outside the temporary build directory. \n\n### path\n\nAdded in [API level 4.0.0](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun path(any: Any): Unit\n```\n\nSpecifies the relative path to your Android.mk build script.\n\nFor example, if your ndk-build script is in the same folder as your project-level\n`build.gradle` file, you simply pass the following: \n\n```text\nandroid {\n externalNativeBuild {\n ndkBuild {\n // Tells Gradle to find the root ndk-build script in the same\n // directory as the project's build.gradle file. Gradle requires this\n // build script to add your ndk-build project as a build dependency and\n // pull your native sources into your Android project.\n path \"Android.mk\"\n }\n }\n}\n```\n\nProperties\n----------\n\n### buildStagingDirectory\n\nAdded in [API level 3.0.0](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract var buildStagingDirectory: File?\n```\n\nSpecifies the path to your external native build output directory.\n\nIf you do not specify a value for this property, the Android plugin uses the\n`\u003cproject_dir\u003e/.cxx/` directory by default.\n\nIf you specify a path that does not exist, the Android plugin creates it for you.\nRelative paths are relative to the `build.gradle` file, as shown below: \n\n```text\nandroid {\n externalNativeBuild {\n ndkBuild {\n // Tells Gradle to put outputs from external native\n // builds in the path specified below.\n buildStagingDirectory \"./outputs/ndk-build\"\n }\n }\n}\n```\n\nIf you specify a path that's a subdirectory of your project's temporary `build`\ndirectory, you get a build error. That's because files in this directory do not\npersist through clean builds.\nSo, you should either keep using the default `\u003cproject_dir\u003e/.cxx/`\ndirectory or specify a path outside the temporary build directory. \n\n### path\n\nAdded in [API level 2.2.0](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract var path: File?\n```\n\nSpecifies the relative path to your Android.mk build script.\n\nFor example, if your ndk-build script is in the same folder as your project-level\n`build.gradle` file, you simply pass the following: \n\n```text\nandroid {\n externalNativeBuild {\n ndkBuild {\n // Tells Gradle to find the root ndk-build script in the same\n // directory as the project's build.gradle file. Gradle requires this\n // build script to add your ndk-build project as a build dependency and\n // pull your native sources into your Android project.\n path \"Android.mk\"\n }\n }\n}\n```"]]