Reputation: 529
We have a quite large C++ project that we build cross platform for Android and iOS. Xcode uses all cores when compiling and is much faster (4-5x depending on machine). Is there any way to improve the abysmal performance of the NDK? Any multi CPU options? We have precompiled headers, but it seems to me it is use of resources that is at fault.
So any tips or tricks to speed up android ndk project build times would be much appreciated!
Upvotes: 19
Views: 10777
Reputation: 108
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.
Upvotes: 3
Reputation: 1100
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
}
}.....
Upvotes: 4
Reputation: 39807
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.
Upvotes: 20