Parallel NDK build in Android Studio

2,320 views
Skip to first unread message

Davy Wentzler

unread,
May 6, 2017, 8:42:21 AM5/6/17
to android-ndk
Hi guys,

After a long time, I decided to give Android Studio a go. I have been using Eclipse until now with ndk-build called separately using a cygwin terminal. I use the parallel build option, 'ndk-build -j6' for example, which gives a huge compilation speed boost on my Core i7 6700K system. I could not find an option for that in Android studio. After Googling around, I found people mentioning to use the 'arguments' option, but that was for early version it seems since that just gives an error.

Is there any way to call ndk-build with the -j argument?

javacom

unread,
May 7, 2017, 1:43:11 AM5/7/17
to andro...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/cca92acd-3910-4c90-ba32-6b1594d56b40%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Davy Wentzler

unread,
May 8, 2017, 4:48:02 AM5/8/17
to android-ndk
I tried:
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
arguments "-j6"
}
}

Gradle sync failed: Could not find method arguments() for arguments [-j6] on object of type com.android.build.gradle.internal.dsl.NdkBuildOptions.

javacom

unread,
May 8, 2017, 8:22:47 PM5/8/17
to andro...@googlegroups.com
I think you should try it in

defaultConfig {
     applicationId "....."
     ....
     externalNativeBuild {
            ndkBuild {
                    arguments "-j6"

not the ndkBuild with path ...

Regards

Iliya Koreshev

unread,
May 8, 2017, 8:22:57 PM5/8/17
to android-ndk
Here is what I have in the native build block for AS 2.3 and it seems to work fine (one difference I see is that I define the arguments inside the defaultConfig block and not the one outside of that block, not sure if that makes a difference:

    defaultConfig {
        applicationId "com.my.app"
        minSdkVersion minSdk
        targetSdkVersion 25
        versionCode 1
        versionName "0.0.1"
        multiDexEnabled true

        externalNativeBuild {
            ndkBuild {
                targets "ndkTarget"

                arguments "NDK_MODULE_PATH:=../../../libs",
                        "NDK_TOOLCHAIN_VERSION:=clang",
                        "-j6",
                        "-d",
                        "APP_SHORT_COMMANDS=true",
                        'NDK_DEBUG=1'
            }
        }
    }

    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }

Davy Wentzler

unread,
May 18, 2017, 3:54:09 PM5/18/17
to android-ndk
Thanks! That seems to have worked.

I see it builds both debug and release, whereas the ndk-build I used from cygwin only did one of them (probably release since my Application.mk contained an APP_OPTIM:= release option). Is this done to be able to debug native code and can I disable one or the other to speed up things even more?

Gerry Fan

unread,
May 19, 2017, 10:50:10 AM5/19/17
to android-ndk
I use command line to do specific build:
   gradlew assembleDebug
   gradlew assembleRelease
   gradlew assemble ( it does both release and debug, I think )

Inside Android Studio IDE, I mostly build debug with "Build Variants":
  inside IDE, left bottom edge ( menu on left side edge ), click on "Build Variants", choose "Debug"

mike digioia

unread,
May 22, 2017, 4:28:54 PM5/22/17
to andro...@googlegroups.com
what is the benefit to doing this?

To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.

To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
Reply all
Reply to author
Forward
0 new messages