First of all, assume that you have installed the environment, and there are a lot of online materials. If you are smart, you will.
1. Compile a class with Native in eclipes and compile it into a class file.
Ex:
[Java]
Publicclass JNI
{
Publicnativevoid write ();
Publicnative String sayHello ();
Publicnativeint plus (int a, int B );
}
2. open the file directory in cygwin to the upper level of the class package name
Ex:
$ Cd/cygdrive/f/AndriodWorkSpace/TestJni/bin/classes
Then generate the header file
$ Javah-classpath.-jni com. emg. mini. JNI
The generated header file is in:
Header file content:
PS: Of course, you can also generate the header file in cmd:
3. Write the corresponding. c file or. cpp File Based on the generated header file. Note the naming rules of function names: Java _ package name_classname_function Name:
4. Compile the Android. mk File
5. Put the compiled files in the jni folder.
6. Next, the most important step is to generate the library file. so.
Open the jni directory in Cygwin:
Enter $ NDK/ndk-build. NDK is the last two sentences of the name you wrote in cygwin Configuration:
Mine is:
The compiled result is as follows:
The obj and libs folders are generated in your directory.
Main Program:
Then you run your program and find something?