Starting address: http://www.eoeandroid.com/thread-201993-1-1.html
I,
Project Creation 1. Create an android project, configure the development environment, load the SDK of the corresponding version, select File> New> project to create a project, and select Android project as the project type, as shown in:
Click Next and enter the expected project name, Android SDK version, and application in the project property options. Program Name, package name, activity class name, and other information, and then click Finish to complete the creation. 1. Add the folders and files required by ndk to create a new folder JNI under the project folder, and use the folder JNI as the file of the C source file. The example of the project directory is as follows:
As shown in:
II,
Ndk
Part 1. C or CPP files used for ndk development are usually stored in the JNC directory, and the files must contain JNI. h header file to provide support for JNI. The program must comply with the JNI call interface specifications. For details, see JNI usage specification. 2. add the MK file to the JNI directory and add android. MK file. The file class is as follows: The local_path statement specifies the compilation path, the local_module specifies the name of the shared library generated by compilation, and the local_src_files statement specifies the compilation file name.
3. Generate the so shared library. Open the cygwin program and enter the JNI folder of the project. Then run the ndk-build file under the ndk folder to generate the shared library.
After compilation is completed, you can view the generated shared library in the libs/armeabi folder of the project. The directory example is as follows:
So far, The shared library is partially complete.
III,
Java
Part 1. Add the local interface of the class to add the function interface in the class implementation. The interface declaration native indicates that the implementation uses the shared library method and loads the corresponding shared library.
2.MkFile Addition
Add the Android. mk file in the JNI directory. The file class is as follows:
2. The method for calling a local interface is no different from that for calling other interfaces. The result is as follows:
Source code: ndkdemo.rar