# NdkBuild

# NdkBuild

<br />

```
public interface NdkBuild
```

<br />

*** ** * ** ***

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](https://developer.android.com/studio/projects/add-native-code.html)

If you want to instead build your native libraries using CMake, see[Cmake](https://developer.android.com/reference/tools/gradle-api/8.3/null/com/android/build/api/dsl/Cmake)

## Summary

|                                        ### Public methods                                         |
|---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract void`                                                                                   | [buildStagingDirectory](https://developer.android.com/reference/tools/gradle-api/8.3/null/com/android/build/api/dsl/NdkBuild#buildStagingDirectory(kotlin.Any))`(@`[NonNull](https://developer.android.com/reference/tools/gradle-api/8.3/null/androidx/annotation/NonNull)` `[Object](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Object.html)` any)` Specifies the path to your external native build output directory. |
| `abstract `[File](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html) | [getBuildStagingDirectory](https://developer.android.com/reference/tools/gradle-api/8.3/null/com/android/build/api/dsl/NdkBuild#getBuildStagingDirectory())`()` Specifies the path to your external native build output directory.                                                                                                                                                                                                                   |
| `abstract `[File](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html) | [getPath](https://developer.android.com/reference/tools/gradle-api/8.3/null/com/android/build/api/dsl/NdkBuild#getPath())`()` Specifies the relative path to your`Android.mk`build script.                                                                                                                                                                                                                                                           |
| `abstract void`                                                                                   | [path](https://developer.android.com/reference/tools/gradle-api/8.3/null/com/android/build/api/dsl/NdkBuild#path(kotlin.Any))`(@`[NonNull](https://developer.android.com/reference/tools/gradle-api/8.3/null/androidx/annotation/NonNull)` `[Object](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Object.html)` any)` Specifies the relative path to your`Android.mk`build script.                                         |
| `abstract void`                                                                                   | [setBuildStagingDirectory](https://developer.android.com/reference/tools/gradle-api/8.3/null/com/android/build/api/dsl/NdkBuild#setBuildStagingDirectory(java.io.File))`(`[File](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html)` buildStagingDirectory)` Specifies the path to your external native build output directory.                                                                                         |
| `abstract void`                                                                                   | [setPath](https://developer.android.com/reference/tools/gradle-api/8.3/null/com/android/build/api/dsl/NdkBuild#setPath(java.io.File))`(`[File](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html)` path)` Specifies the relative path to your`Android.mk`build script.                                                                                                                                                  |

## Public methods

### buildStagingDirectory

```
abstract void buildStagingDirectory(@NonNull Object any)
```

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:  

```text
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  

### getBuildStagingDirectory

```
abstract File getBuildStagingDirectory()
```

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:  

```text
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  

### getPath

```
abstract File getPath()
```

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:  

```text
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  

### path

```
abstract void path(@NonNull Object any)
```

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:  

```text
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  

### setBuildStagingDirectory

```
abstract void setBuildStagingDirectory(File buildStagingDirectory)
```

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:  

```text
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  

### setPath

```
abstract void setPath(File path)
```

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:  

```text
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