[]ubuntu integration Eclipse and Javah generate JNI header file to develop Android native program

Source: Internet
Author: User

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
  1. /* Don't EDIT this file-it are machine generated */
  2. #include <jni.h>
  3. /* Header for class com_hello_word_hellowordactivity */
  4. #ifndef _included_com_hello_word_hellowordactivity
  5. #define _included_com_hello_word_hellowordactivity
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /*
  10. * Class:com_hello_word_hellowordactivity
  11. * Method:sayhello
  12. * Signature: () ljava/lang/string;
  13. */
  14. Jniexport jstring Jnicall Java_com_hello_word_hellowordactivity_sayhello
  15. (JNIENV *, jobject);
  16. #ifdef __cplusplus
  17. }
  18. #endif
  19. #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
  1. /* Don't EDIT this file-it are machine generated */
  2. #include <jni.h>
  3. /* Header for class com_hello_word_hellowordactivity */
  4. #ifndef _included_com_hello_word_hellowordactivity
  5. #define _included_com_hello_word_hellowordactivity
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /*
  10. * Class:com_hello_word_hellowordactivity
  11. * Method:sayhello
  12. * Signature: () ljava/lang/string;
  13. */
  14. Jniexport jstring Jnicall Java_com_hello_word_hellowordactivity_sayhello
  15. (JNIENV *, jobject);
  16. #ifdef __cplusplus
  17. }
  18. #endif
  19. #endif

[]ubuntu integration Eclipse and Javah generate JNI header file to develop Android native program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.