Friday, September 2, 2016

JNI step by step

1. Add native method in your activity class 
    for instance : public native String display(boolean status);

2. open command prompt and go to bin/classes
    Example :~/workspace/test/bin/classes$ javah -jni com.example.test.MainActivity
    Abstract :~/workspace/test/bin/classes$ javah -jni <class name where u have added your native API> 

    as a result , a header file will be created in   "test/bin/classes/" 
3. Copy that header file and paste it in to jni folder (create jni folder in the project )

4. Using signature of the header , create the cpp file and have definition for that method

5. Create Android.mk file (add the cpp file and module name inside it)

6. go to the project 
    Example:~/workspace/test$ "ndk-build.cmd"
    result : this will create lib (under the libs folder)

7. now, you can call the native method from the application

No comments:

Post a Comment