Initial start of JNI

Source: Internet
Author: User

JNI has not been able to learn the system. Revisit the HelloWorld of JNI today main reference http://www.cnblogs.com/yejiurui/p/3476565.html

This article records your feelings.

JNI Development process:

Write native Import class--Write the header file, C code, and configuration android.mk-> Project Call Nvtive class

Attention:

The decorated properties of method declarations in a 1.NATIVE class file are as follows:

 package   Com.tg.hz.hellojni.jni;  public  class   Jniclient { public  native   string Addstr (string stra    , String StrB);  static  public  native  int  addint (int  inta,< Span style= "color: #0000ff;"    >int   IntB);  static   {system.loadlibrary ( "    Hellojnitest "); }}

2. Generate the class file: Cmd-javac (compile Native entry class file) to generate the bytecode (. Class) file, if you use Eclipse as the editor, you can *\ find the file in the project folder Bin\classes\ (package name)

3. Generate. h header file: Cmd->javah (Edit the class file in the previous step) it is easier to make an editor with Eclipse, such as

CMD under the project bin\classes file. Use the Javah package name + class name (class name does not have a suffix) to generate a. h file in the classes current directory

If you are not using the Eclipse Editor. Or there is no classes corresponding folder. It is necessary to establish the following folder tree according to the package name + class name (important), and then navigate to the COM sibling directory in cmd using the Javah package name + Class name (the class name does not have a suffix), a. h file is generated in the current directory

3. Copy the header file to the Jni folder. Create a C or CPP file with the same name and reference the header file

4.android.mk

Local_path: = $ (call My-dir) include $ (clear_vars) Local_module: = hellojnitest/* Configuration related to generated so file name and System.load The call in the Library ("Hellojnitest") */local_src_files: = com_tg_hz_hellojni_jni_jniclient.c/* Configure the C or CPP file name that needs to be compiled under JNI */include $ (build_shared_library)

5. The project address is then on the head

Initial start of JNI

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.