Skip to content Skip to sidebar Skip to footer

Android Ndk Build With Ant Script

Can we use the ANT script for Android NDK builds ? If Yes how? And if no, then why Not ? I don't have any idea about it

Solution 1:

Call ndk-build from your -pre-build target, like this:

<targetname="-pre-build"><execexecutable="${ndk.dir}/ndk-build"failonerror="true"/></target><targetname="clean"depends="android_rules.clean"><execexecutable="${ndk.dir}/ndk-build"failonerror="true"><argvalue="clean"/></exec></target>

Then you can set ndk.dir to point at the NDK directory from your local.properties file, or set it on the command line. I do this:

ant -Dsdk.dir=/home/dg/apps/android-sdk-linux_x86-r11/ -Dndk.dir=/home/dg/apps/android-ndk-r6b release

Now running ant will build your native code automatically. Plus, running 'ant clean' will clean your native code.

Updated: Added failonerror="true" to the <exec> tasks --- this causes ant to abort if the make fails. Without it it'll just go right ahead and generate an APK with an invalid binary in it. Not good!

Solution 2:

here is what to add to your build.xml as others stated:

<targetname="-pre-build"><execexecutable="${ndk.dir}/ndk-build"failonerror="true"/></target><targetname="clean"depends="android_rules.clean"><execexecutable="${ndk.dir}/ndk-build"failonerror="true"><argvalue="clean"/></exec></target>

define the ndk.dir in local.properties file: ndk.dir=C:\EclipseWorkspace\android-ndk-r8d

The situation i wanted to mention after doing this you get an error "%1 is not a valid Win32 application" while running ANT against this target override. For me i had to upgrade to NDK R8d and also update the following line so that it fetches ndk-build.cmd (this version of ndk can run on windows and via cygwin:

exec executable="${ndk.dir}/ndk-build.cmd" failonerror="true"

Post a Comment for "Android Ndk Build With Ant Script"