Tuesday, October 25, 2011

How to launch ndk-build from win32 eclipse

I'm now working on Android making jni shared libraries to speed up some image processing algorithms.

I was wondering how to have all the conveniences of Eclipse IDE running under Windows and normal compilation speed of GCC on Linux machine for building Android shared libraries for jni. Cygwin is just too damn slow, it takes ages to compile even a small-sized shared library.

Here's how to run ndk-build on a Linux build machine from the Eclipse IDE running on Windows. I'm assuming your Putty saved session is "Linux-build".

First, make sure you're able to login to linux machine through Putty without password: google://putty+passwordless. Make sure that you have your plink.exe in your Windows PATH environment variable. I'd recommend a very useful utility Path Editor.

Add a new make target in Eclipse: right-click on your project in Eclipse -> Make targets ->Create...
Enter the following command in the "Build Command" input text box:
plink.exe -load "Linux-build" "cd /home/denis/android/myproject/jni; source env.sh; ndk-build"


plink.exe here opens ssh session named "Linux-build" in Putty and executes several bash commands: goes to the jni directory, reads android ndk configuration variables from env.sh and launches the ndk-build script.
It might be useful to add clean command to Eclipse also:
plink.exe -load "Linux-build" "cd /home/denis/android/myproject/jni; source env.sh; ndk-build clean"


Here "Linux-build" is your Putty session name; myproject is the name of the jni project having jni directory inside. My env.sh looks like this:


# env.sh
export ANDROID=/home/denis/android
export ANDROID_SDK_ROOT=${ANDROID}/android-sdk-linux
export NDK=${ANDROID}/android-ndk-r6
export ANDROID_NDK_ROOT=${NDK}
#export TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
export PATH=$PATH:${NDK}:${NDK}/tools
export ANDROID_API_LEVEL=android-5
export NDK_PROJECT_PATH=$ANDROID/myproject



I intentionally use android-ndk-r6 instead of android-ndk-r6b, because of the compilation problem

...arm-linux-androideabi/bin/ld.exe: crtbegin_so.o: No such file: No such file or directory collect2: ld returned 1 exit status

(see related Stackoverflow question)