Use of ANDROID-NDK-R7

Source: Internet
Author: User

ANDROID-NDK-R7 use and configuration has been quite simple, no longer need to Cygwin, do not need to install, only need to extract the environment variables to register.

Register environment variable: Create a new system variable: NDK_HOME=D:\ANDROIDDESIGN\ANDROID-NDK-R7, modify the value of path, increment at last;%ndk_home%.

The NDK can then be used, as the current premise is that Eclipse and the SDK are already set up and ready to use, see other articles on these two settings.

The following is a demonstration using the "Android-ndk-r7\samples\hello-jni" routine.

First, create a new project in Eclipse, choose File-->new-->project, select Android Application project in the popup dialog box, as shown in:


Click "Next" to enter the following interface, enter the project name, here enter the same name as the routine, or in the future when the program will run error.


Next all the way "next", all choose the default value, finally click "Finish" to complete the new project creation.

In the project bar on the left side of Eclipse, right-click on the newly created Hellojni project and select New-->floder to create a new folder named Jni, as shown in

Copy the two files in the Jni folder under the Android-ndk-r7\samples\hello-jni folder to the new Jni folder above and android-ndk-r7\samples\ The Hellojni.java file in the Hello-jni\src\com\example\hellojni is copied to the corresponding directory in the new project.

Right-click on the new Hellojni project and select Properties in the popup menu, as shown in:

Select the builder item on the left side of the pop-up dialog and select New on the right to create a new builder. Select "Program" in the Pop-up dialog and click on the OK button to enter the Edit configuration dialog as shown in the box:

In the Main property page, set as shown, and the location entry is your native NDK directory.

Follow the settings for the Refresh property page:

Follow the settings in the Build Option property page:

Click the Specify Resource button in the new project to select the Jni folder, as shown in:

Click Finish returns, click OK to apply the settings, and then automatically start compiling the program in JNI, as shown in the successful compilation:

Finally, modify the Android:name entry in the Androidmainfest.xml file to change the mainactiveity to Hellojni, as shown in:

Save this file, normally the entire project is compiled correctly at this time.

Right-click on the project name and select Run As-->android application in the pop-up menu to start the virtual machine run program as shown in:

Finally, note: If you create a project name that is not hellojni, you need to modify the function name in the Hello-jni.c file, such as the project name is TESTNDK, then the function name needs to be modified to: Java_com_example_testndk_ HELLOJNI_STRINGFROMJNI,COM_EXAMPLE_TESTNDK is the package name, Hellojni is the class name.

Use of ANDROID-NDK-R7

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.