Use JNI in Android to call C functions in Java

Source: Internet
Author: User

Address: http://blog.csdn.net/ariesjzj/article/details/7388874

The basic step is to first compile the C function into a. So library, and then use the Java masterProgramLoad the database and call the functions through JNI.

 

The first step is to download the ndk. Some of the examples are suitable for getting started. install or decompress them as described in the official document.

 

Step 2: Compile the dynamic link library. Take hello-JNI, one of the samples that comes with ndk as an example. First, enter this directory and run ndk-build (under the ndk directory) to generate the following directories:

Libs: Stripped. So, which is usually used to link to the library of the final app.

OBJ: no stripped. So, debugging information such as this signed Table, can be used in debug.

Assets, Gen, res, and other things

Note that the application. mk in JNI can indicate whether the generated target is for the arm or X86 platform. To compile. So into an x86 Platform, create application. mk under JNI:

App_abi: = x86

 

Step 3: Compile the APK of the entire app. Initially, the project directory generally contains two folders, one JNI, containing the c file, and the other SRC, containing the Java file. After so is compiled in the previous step, use eclipse to import the project (file-> New-> Project-> Android Project). Then, an option is to load the project from an existing project, it automatically parses android. fill in the MK file.

Finally, the runtime in eclipse will automatically generate the final executable file with the so of the specified Platform compiled just now, and automatically package it into the APK. If n devices are connected, remember which one to use before running.

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.