Android ndk Project Creation and compilation

Source: Internet
Author: User
Starting address: http://www.eoeandroid.com/thread-201993-1-1.html I, Project Creation 1. Create an android project, configure the development environment, load the SDK of the corresponding version, select File> New> project to create a project, and select Android project as the project type, as shown in:

Click Next and enter the expected project name, Android SDK version, and application in the project property options. Program Name, package name, activity class name, and other information, and then click Finish to complete the creation. 1. Add the folders and files required by ndk to create a new folder JNI under the project folder, and use the folder JNI as the file of the C source file. The example of the project directory is as follows:

As shown in:

II, Ndk Part 1. C or CPP files used for ndk development are usually stored in the JNC directory, and the files must contain JNI. h header file to provide support for JNI. The program must comply with the JNI call interface specifications. For details, see JNI usage specification. 2. add the MK file to the JNI directory and add android. MK file. The file class is as follows: The local_path statement specifies the compilation path, the local_module specifies the name of the shared library generated by compilation, and the local_src_files statement specifies the compilation file name.

3. Generate the so shared library. Open the cygwin program and enter the JNI folder of the project. Then run the ndk-build file under the ndk folder to generate the shared library.

After compilation is completed, you can view the generated shared library in the libs/armeabi folder of the project. The directory example is as follows:

So far, The shared library is partially complete.

 

III, Java Part 1. Add the local interface of the class to add the function interface in the class implementation. The interface declaration native indicates that the implementation uses the shared library method and loads the corresponding shared library.

2.MkFile Addition

Add the Android. mk file in the JNI directory. The file class is as follows:

2. The method for calling a local interface is no different from that for calling other interfaces. The result is as follows:

Source code: ndkdemo.rar
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.