The entire process of downloading from NDK to JNI calls

Source: Internet
Author: User

All of the following actions are based on the MacBook, and of course the operations on Windows are similar. If your development environment is windows, if you encounter different, ask the degree Niang or Google big God.

Well, the nonsense is not much to say, directly look at the following process:

First, the NDK download

1. Download Connection: Https://developer.android.com/tools/sdk/ndk/index.html#Downloads

In particular: If you can't access Google, download a hosts file on GitHub and replace your computer's Hosts file. Both Mac and windowns have hosts files:

Hosts file path under Mac: Mail Click Finder, select Go to Folder, enter/PRIVATE/ETC in the input box, click Go. Finally, replace the hosts file under File/private/etc.

Windows under the Hosts file path: Enter the C drive, double-click the "windows" → "System32" → "Drivers" → "etc", and finally replace the hosts file.

Because Google's I address will often change, if you find that you have replaced the Hosts file or do not have access to Google, then download a Hosts file from GitHub to try again. It technology will be the courage to try.

Okay, here's the point.

2. Execute the command:

chmod a+x Android-NDK-r10c-Darwin-x86_64.bin./Android-NDK-r10c-Darwin-x86_64.bin

namely: Punch-in Terminal command window, enter the file directory where you downloaded the NDK, enter the above two lines sequentially. The goal is to extract the. bin file into a folder, otherwise you cannot use it directly.

Ii. Configuring the NDK plug-in in eclipse

To:eclipse--> Preferences (preference)-->ANDROID-->NDK, select the Ndk folder you just unzipped in the NDK loactiion input box and click Apply/ok.

So the NDK configuration is done, isn't it simple?

Iii. NDK compilation generates. so Files

1. Right-click on your selected Android project and select Add Native support ... in the list of Android tools, then enter your. So file name in the input box and click Finish.

2. The Jni folder is then automatically generated in your project, and there is a android.mk file and a. c (or. cpp) file in the folder. Note:. c files are written in C, and. CPP is written in the C + + language, and if you generate a. cpp file, you can also modify this file directly to a. c file, which is not a problem. (If you want to know the contents of the code inside these two files, please download the document: Http://pan.baidu.com/s/1pJn3Eun, Password: GBKR. Open the downloaded Word document, command+f and then enter the keyword NDK to retrieve the relevant content for understanding. )

3. After writing the. C or. cpp file, the running project will be compiled automatically, and the compilation will generate a. So file in the libs/armeabi/directory. The name of the file is libxxx.so. (XXX is the name of the. So file you entered above yourself)

Iv. how to invoke the Jni interface

1. First on a demo:https://github.com/lzyickobe/uninstalldemo/, this demo is how the application listens to its own uninstall.

2. A more detailed explanation of this demo document: http://lzyblog.com/2015/01/09/Android%E5%BA%94%E7%94%A8%E7%9B%91%E5%90%AC%E8%87%AA%E5%B7% b1%e6%98%af%e5%90%a6%e8%a2%ab%e5%8d%b8%e8%bd%bd%ef%bc%8c%e5%81%9a%e5%8f%8d%e9%a6%88%e7%bb%9f%e8%ae%a1/

3. places of special attention : When calling method system. loadLibrary ("") to load the. So file, remove the Lib prefix in front of the. so file, otherwise it will report an exception: Unsatisfiedlinkerror.

For example:System. loadLibrary ("libxxx") is the wrong wording; System. loadLibrary ("XXX") is the correct wording.


There's nothing else to say about it. Like this summary article, I write very little, perhaps some places to write to let everybody feel not particularly clear. Please leave a message or send to e-mail: [email protected]. Welcome everyone to communicate at any time, so as to progress together.


The entire process of downloading from NDK to JNI calls

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.