Nuffnang Ads

Sunday, 25 March 2012

Android NDK tutorial (JNI)

JNI stands for Java native interface that enable Java to use Native application or library such as C/C++ or assembly in Java application.
1. Before following this tutorial, all those software should be installed and downloaded first :

a) Eclipse
b) Android SDK
c) Android NDK
d) Cygwin (for windows user)

2. Create new project. Then create ‘jni’ folder in project file
3. Edit .java file to integrate with JNI
4. Create “hello-jni.c” in “jni” folder (right click on “jni” folder>>new>>File
5. Paste source code as shown (make sure package name is correct: mine use “com.example.hellojni”) in 
    this .c file, jstring 
    - Java_com_example_hellojni_HelloJni_stringFromJNI (red:package,purple:java class that jump to
       .c file, blue: function name in java class)

6. Under “jni” folder, create “” file. (same procedure as created .c file)
7. Native Compilation
    - Use cygwin to compile native part ( go to project folder using cygwin command line and type file path
      for ndk-build in android-ndk)
    - If the compilation with no error, it will generate .so file
8. Run (running on galaxy y)

1 comment:

  1. i need full tutorial about jni please send update and send me the deatails in