Android NDK learning summary, androidndk Summary
1. android NDK programming steps
- Declare the native method in the java file.
- Create a jni folder in the root directory of the android project.
- Call the javah command to generate the corresponding. h header file for the native method declared in step 1.
Run the following statement in the root directory of the project in the windows command line window to generate the corresponding. h header file:
Javah-classpath bin/classes; D: \ yinz \ adt-bundle-windows-x86_64-20131030 \ sdk \ platforms \ android-19 \ android. jar-d jni com. example. hellondk. MainActivity
You can enter javah in the command line and press enter to view the related parameters of the javah command.
After the command is executed, the corresponding. h header file is generated in the jni folder under the root directory of the project.
- Create a. c source file in the jni directory and implement the method in. h.
- Compile the android. mk file (copy the android. mk file in the NDK demo. After the file is copied, modify the corresponding parameters, such as the generated. so file name and the. c source file to be compiled ).
The samples of the NDK decompression package stores the demo project in the folder.
- Run the root directory of the project: ndk-build to generate the corresponding. so file (this step can be omitted if eclipse is configured to compile automatically ).
- Load the. so file in java and call this method.
Ii. eclipse-related configuration
- Configure eclipse to automatically compile and generate the. so file
Right-click the android project and choose properties as follows:
Run "-->" External Tools "-->" External Tools deployments ", the following Configuration box is displayed:
Javah generates the header file and javap to view the method signature, instead of entering a long string of commands in the command line window to execute the corresponding operation. The method signature is used when the java object method is called in the jni function.
- Code prompt when JNI encoding is configured
Right-click the project and choose --> "Android Tools" --> "Add Native Support" --> "finish ".
Then, right-click the project and choose --> "Properties", as shown in the following figure:
Android-ndk-r10b \ platforms \ android-L \ arch-arm \ usr \ include
After the configuration, you can use the eclipse code prompt function to prompt the jni method when writing the corresponding jni method.