Android JNI calls the Ndk method

Source: Internet
Author: User

Preparatory work:

1. Need to install JDK, I am using JDK 1.7.0;

2. Install NDK, I am using the version of Android Studio automatically downloaded;

Now to implement this invocation process:

1. Create a new project: Myjnitest

Activity_main.xml (for displaying test results);

2. Create a new Java class under Com.example.myapplication Jnitext

What's Inside:

3. Compile the project myjnitest, myjnitest corresponding Build\intermediates\classes\debug in the project will generate the Jnitext. class file;

4. In the myjnitest\build\intermediates\classes\debug directory, CMD uses the Javah command to generate the jnitext corresponding header file;

Command: Javah-classpath. Com.example.myapplication.JniText generate com_example_myapplication_jnitext.h file;

5. Create folder JNI in the Myjnitest project, remember to select

6. Cut the file com_example_myapplication_jnitext.h to the JNI directory and create the com_example_myapplication_jnitext.h corresponding. c file under that directory;

:

Write a. c file :

7. Modify the build.gradle file corresponding to the project:

8. Modify the gradle.properties file: Add android.usedeprecatedndk=true;

9. Call the method in Jnitext:

10: Run Result:

Success!!!!


Android JNI calls the Ndk method

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.