Preparatory work:
1. Need to install JDK, I am using JDK 1.7.0;
2. Install NDK, I am using the version of Android Studio automatically downloaded;
Now to implement this invocation process:
1. Create a new project: Myjnitest
Activity_main.xml (for displaying test results);
2. Create a new Java class under Com.example.myapplication Jnitext
What's Inside:
3. Compile the project myjnitest, myjnitest corresponding Build\intermediates\classes\debug in the project will generate the Jnitext. class file;
4. In the myjnitest\build\intermediates\classes\debug directory, CMD uses the Javah command to generate the jnitext corresponding header file;
Command: Javah-classpath. Com.example.myapplication.JniText generate com_example_myapplication_jnitext.h file;
5. Create folder JNI in the Myjnitest project, remember to select
6. Cut the file com_example_myapplication_jnitext.h to the JNI directory and create the com_example_myapplication_jnitext.h corresponding. c file under that directory;
:
Write a. c file :
7. Modify the build.gradle file corresponding to the project:
8. Modify the gradle.properties file: Add android.usedeprecatedndk=true;
9. Call the method in Jnitext:
10: Run Result:
Success!!!!
Android JNI calls the Ndk method