Configure the Android NDK development environment in Mac OS X

Source: Internet
Author: User

Configure the Android NDK development environment in Mac OS X

1. Before reading the following, make sure that the development environment of your Android sdk has been set up, and the ADT should be the latest.

2. download the latest ndk at http://developer.android.com/tools/sdk/ndk/index.html.

3. decompress the downloaded file.

4. Configure your. bash_profile. Open the terminal and enter the command pico. bash_profile.

Add a row of export PATH =$ {PATH}:/Users/jarrahwu/Documents ents/android-ndk-r8d first

Then a line of A_NDK_ROOT =/Users/jarrahwu/Documents/android-ndk-r8d

Last line export A_NDK_ROOT

This is actually equivalent to saving the environment variable contrl + x in windows, then entering Y to confirm, and finally entering enter. Finally, close the terminal and open it again.

 

For more information, see my uploaded images.

If the above configuration is correct, you can prepare to write an ndk hello world.

(1) first, create a project named MyNDK, just like setting up an android project.

(2) configure the android NDK path. The specific operation is-> eclipse-> preferences-> android-> NDK, and then configure your NDK path.

(3) If you are not the latest ADT, you may need to use the javah command on the terminal to add NDK support, create folders, and so on, however, the latest ADT already contains some columns for these operations. you can simply add NDK support.

Right-click your project and choose android tools> Add Native Support .. all of a sudden OK. if your eclipse cannot view the c file, you need to add CDT support.

An NDK project is created easily.

Next we will go to the Code section. Let's start with the java section. In your activity, we mainly call your ndk Library and the Library method.

 

The following is the key part. c. I encountered many errors at that time. Pay special attention to the format and specifications. check the Code directly. be sure to declare your method at the beginning of this extern. Otherwise, an error is returned.

 

Finally, let's run it. Let's see the effect ..

 

If there is something wrong with this article, I hope to make a lot of bricks.

This article permanently updates the link address:

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.