How to speed up android ndk builds

For everyone receiving the following error

Could not find method arguments() for arguments [-jx] on object of type com.android.build.gradle.internal.dsl.NdkBuildOptions.

There is a difference between

android.externalNativeBuild (here) and

android.defaultConfig.externalNativeBuild (here).

android.defaultConfig.externalNativeBuild accepts arguments and can be used to set -j option.


You aren't required to use Android's build system for your compilation; the tools are all available for use within a Makefile (though you will need to take care to set up include paths, library paths, and compiler options).

Since you can create your own Makefile instead of using the default build scripts, you can use th -jN option to specify the number of simultaneous operations to perform.


Following fragment of bulid.gradle shows an example of -jN and abifilters : (see http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.ExternalNativeNdkBuildOptions.html and https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.NdkOptions.html)

android {
compileSdkVersion 21
buildToolsVersion '25.0.3'

defaultConfig {
    applicationId "test"
    minSdkVersion 21
    targetSdkVersion 21

    ndk {
        moduleName "native_lib"
        abiFilters 'armeabi-v7a', 'arm64-v8a'
    }
    externalNativeBuild {
        ndkBuild {
            arguments '-j4'
        }
    }
    jackOptions {
        enabled true
    }
}.....