Reprinted from: http://blog.csdn.net/jiuyueguang/article/details/9404237
This article describes two methods for generating JNI header files using the Javah command, the first known Javah command, and the second for integration Javah into eclipse. recommend the second way, easy and fast, at any time to modify the generation of
0: Prerequisites and Conditions:
1:ubuntu64 bit System
2:ANDROID-NDK-R8E is already installed and configured into eclipse.
3:android-sdk-linux is already installed and configured into eclipse.
1: First command-line mode
1: The structure of my project is like this, my
, using the eclipse automatically generated Jni folder, you can see ANDROID.MK and hello.cpp, at this time there is nothing in hello.cpp, below we use terminal commands to enter the project folder, and then into the bin/ Classes folder (The reason why it is not in the project directory to go to the Bin/classes folder is because it is convenient to use the TAB key to knock out the class name, without error), the structure
Use the TAB key to knock out this and then remove the back class and replace/for. Walk
Where-D is the generated directory folder, replace with, and then enter
You can enter the JNI folder to see the generated. h header File
View files as
[HTML]View Plaincopy
- /* Don't EDIT this file-it are machine generated */
- #include <jni.h>
- /* Header for class com_hello_word_hellowordactivity */
- #ifndef _included_com_hello_word_hellowordactivity
- #define _included_com_hello_word_hellowordactivity
- #ifdef __cplusplus
- extern "C" {
- #endif
- /*
- * Class:com_hello_word_hellowordactivity
- * Method:sayhello
- * Signature: () ljava/lang/string;
- */
- Jniexport jstring Jnicall Java_com_hello_word_hellowordactivity_sayhello
- (JNIENV *, jobject);
- #ifdef __cplusplus
- }
- #endif
- #endif
The generated header file is correct
2: Second way: Integrate Ecipse and Javah commands
1:: In the click of the mouse position in the lower triangle, under Ubuntu, the picture is very laborious, select the second Externel tools configurations
2: A dialog box appears, followed by a few notes:
1:name write Javah.
2:location is the directory where your Javah is located
3:working directory fill it in.
4:arguments Fill in
The last apply is the right,
Then put the mouse on the Hellowordactiviry.java, and notice that it's not on the project.
Then click on the button just now, point this green, not the right triangle, and then you will see the JNI directory under the header file,
The same is the correct code
[HTML]View Plaincopy
- /* Don't EDIT this file-it are machine generated */
- #include <jni.h>
- /* Header for class com_hello_word_hellowordactivity */
- #ifndef _included_com_hello_word_hellowordactivity
- #define _included_com_hello_word_hellowordactivity
- #ifdef __cplusplus
- extern "C" {
- #endif
- /*
- * Class:com_hello_word_hellowordactivity
- * Method:sayhello
- * Signature: () ljava/lang/string;
- */
- Jniexport jstring Jnicall Java_com_hello_word_hellowordactivity_sayhello
- (JNIENV *, jobject);
- #ifdef __cplusplus
- }
- #endif
- #endif
[]ubuntu integration Eclipse and Javah generate JNI header file to develop Android native program