Android + NDK + cygwin Programming

Source: Internet
Author: User

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?

 

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.