Android calls the entire JNI process for later operations. Android calls the entire JNI process for later operations.

Source: Internet
Author: User

Original article: Android calls the JNI process to facilitate subsequent operations.

I personally recorded the entire process of calling JNI, and I forgot to save it. Ah.
In some cases, the ndk environment and ndk source code must be prepared. cygwin must be installed with a profile. Java requires environment variables.

1. Create a new project and create a class to declare the method that calls native.

Package com. Stay. JNI;

Public class callnative {
Public callnative (){
}

Static {// remove the preceding lib from the imported lib name
System. loadlibrary ("Skytech ");
}

Public native byte [] readcmd (string path );

Public native int writecmd (byte [] cmd, string path );
}

2. Build the project, open cmd, CD to the bin directory of the project,
D: \> Cd D: \ Android \ rayn \ testjni \ bin

D: \ Android \ rayn \ testjni \ bin> javah-JNI com. Stay. JNI. callnative

Then a. h file will appear in the bin directory. This is the declared header file.

3. What we need is the method declared in it. Just change the c file we want to write to the same method name. (I wrote the implementation into the. h file and kept compiling with the. h file .. =)

4. Create a JNI directory in the project and copy the changed C file and MK file (copy one file at will, change the path and Lib name) to the directory.

5. Compile the program according to the ndk method:

    1. Place your native sources under<Project>/JNI /...
    2. Create<Project>/JNI/Android. mkTo describe your native sources to the ndk build system
    3. Optional: Create<Project>/JNI/application. mk.
    4. Build your native code by running the 'ndk-build' script from your project's directory. It is located in the top-level ndk directory:
      CD <project> <ndk>/ndk-build

      The build tools copy the stripped, shared libraries needed by your application to the proper location in the application's

I personally recorded the entire process of calling JNI, and I forgot to save it. Ah.
In some cases, the ndk environment and ndk source code must be prepared. cygwin must be installed with a profile. Java requires environment variables.

1. Create a new project and create a class to declare the method that calls native.

Package com. Stay. JNI;

Public class callnative {
Public callnative (){
}

Static {// remove the preceding lib from the imported lib name
System. loadlibrary ("Skytech ");
}

Public native byte [] readcmd (string path );

Public native int writecmd (byte [] cmd, string path );
}

2. Build the project, open cmd, CD to the bin directory of the project,
D: \> Cd D: \ Android \ rayn \ testjni \ bin

D: \ Android \ rayn \ testjni \ bin> javah-JNI com. Stay. JNI. callnative

Then a. h file will appear in the bin directory. This is the declared header file.

3. What we need is the method declared in it. Just change the c file we want to write to the same method name. (I wrote the implementation into the. h file and kept compiling with the. h file .. =)

4. Create a JNI directory in the project and copy the changed C file and MK file (copy one file at will, change the path and Lib name) to the directory.

5. Compile the program according to the ndk method:

    1. Place your native sources under<Project>/JNI /...
    2. Create<Project>/JNI/Android. mkTo describe your native sources to the ndk build system
    3. Optional: Create<Project>/JNI/application. mk.
    4. Build your native code by running the 'ndk-build' script from your project's directory. It is located in the top-level ndk directory:
      CD <project> <ndk>/ndk-build

      The build tools copy the stripped, shared libraries needed by your application to the proper location in the application's

Related Article

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.