Tuesday, December 11, 2012

Speed up your Android NDK build

Because of a bug in the recent NDK-r8c release which effectively causes all builds to be clean builds, my frustrations with our Android build time reached a tipping point.

First the fix to the r8c build bug:  http://quirkygba.blogspot.com/2012/11/two-problems-with-android-ndk-r8c.html (one character change (how does this crap get shipped?))

Second, I noticed my iMac was all to quiet after these build sessions, leading me to investigate and discover the somewhat obvious fact that g++ was only running on one core.

The way a typical Android build stack with ndk works is:
Ant  »  ndk-build  »  gnu Make  »  g++/gcc
Anything you pass to ndk-build in the form of command like args gets passed to Make. so the trick was a quick search for where to put some Make concurrency args in the ant build files.

I'm using the "jobs" flag to parallelize Make. -j4 for 4 jobs, -j8 for 8 and so on.

Typically you will have a build.xml in your Android directory which may contain everything or likely is a standard build.xml which imports custom rules (custom_rules.xml in our case). Wherever your ant files describe executing ndk-build you want to add:
<arg value="-j8">
To zoom out a little:
<target name="-pre-build">
  <exec executable="${ndk.dir}/ndk-build"..>
    <arg value="-j8"/>
    ...
  </exec>
</target>
Can't wait to see how fast it builds on the new iMac!

No comments:

Post a Comment