Firebird News

Thursday, January 06, 2011

Hello from jni (native code) in Android

I wish that android ndk to be merged into sdk so we have one less step after installing the sdk

The NDK includes sample applications that illustrate how to use native code in your Android applications:

* hello-jni — a simple application that loads a string from a native method implemented in a shared library and then displays it in the application UI.


I unziped the ndk into my home /home/mariuz/android-ndk-r4b
added it to path
vi /home/mariuz/.bashrc

and added this line

export PATH=${PATH}:/home/mariuz/android-sdk-linux_x86/tools:/home/mariuz/android-ndk-r4b:
the use the build-ndk to build the shared library
cd /home/mariuz/android-ndk-r4b/samples/hello-jni/
ndk-build 
Gdbserver      : [arm-eabi-4.4.0] /home/mariuz/android-ndk-r4b/samples/hello-jni/libs/armeabi/gdbserver
Gdbsetup       : /home/mariuz/android-ndk-r4b/samples/hello-jni/libs/armeabi/gdb.setup
Gdbsetup       : + source directory /home/mariuz/android-ndk-r4b/samples/hello-jni/jni
Compile thumb  : hello-jni <= /home/mariuz/android-ndk-r4b/samples/hello-jni/jni/hello-jni.c
SharedLibrary  : libhello-jni.so
Install        : libhello-jni.so => /home/mariuz/android-ndk-r4b/samples/hello-jni/libs/armeabi


Next, build the sample Android applications that use the shared libraries:

* If you are developing in Eclipse with ADT, use the New Project Wizard to create a new Android project for each sample, using the "Import from Existing Source" option and importing the source from /samples/hello-jni/. Then, set up an AVD, if necessary, and build/run the application in the emulator.

No comments: