Stay organized with collections
Save and categorize content based on your preferences.
NdkBuild
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 functions |
Unit |
Specifies the path to your external native build output directory.
|
Unit |
Specifies the relative path to your Android.mk build script.
|
Public properties |
File? |
Specifies the path to your external native build output directory.
|
File? |
Specifies the relative path to your Android.mk build script.
|
Public functions
buildStagingDirectory
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.
since 4.0.0
path
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"
}
}
}
since 4.0.0
Public properties
buildStagingDirectory
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.
since 3.0.0
path
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"
}
}
}
since 2.2.0
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```\ninterface NdkBuild\n```\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nDSL object for per-module ndk-build configurations, such as the path to your `Android.mk` build 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 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](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/8.1/com/android/build/api/dsl/Cmake)\n\nSummary\n-------\n\n| ### Public functions ||\n|------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [buildStagingDirectory](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/NdkBuild#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| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [path](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/NdkBuild#path(kotlin.Any))`(any: `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)`)` Specifies the relative path to your `Android.mk` build script. |\n\n| ### Public properties ||\n|-------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [File](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html)`?` | [buildStagingDirectory](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/NdkBuild#buildStagingDirectory()) Specifies the path to your external native build output directory. |\n| [File](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html)`?` | [path](/reference/tools/gradle-api/8.1/com/android/build/api/dsl/NdkBuild#path()) Specifies the relative path to your `Android.mk` build script. |\n\nPublic functions\n----------------\n\n### buildStagingDirectory\n\n```\nfun 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 `\u003cproject_dir\u003e/.cxx/` directory by default.\n\nIf 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: \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` 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 `\u003cproject_dir\u003e/.cxx/` directory or specify a path outside the temporary build directory.\n\nsince 4.0.0 \n\n### path\n\n```\nfun 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 `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\nsince 4.0.0\n\nPublic properties\n-----------------\n\n### buildStagingDirectory\n\n```\nvar 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 `\u003cproject_dir\u003e/.cxx/` directory by default.\n\nIf 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: \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` 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 `\u003cproject_dir\u003e/.cxx/` directory or specify a path outside the temporary build directory.\n\nsince 3.0.0 \n\n### path\n\n```\nvar 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 `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\nsince 2.2.0"]]