Android NDK Environment Setup

Source: Internet
Author: User

If you want to open a high-efficiency software on Android, or need to use the C + + language, in order to develop the C + + language on Java need to install the NDK on the IDE, the Android Web SDK development environment has included the ADT plugin, The latest Android development IDE can be downloaded from the website: http://developer.android.com/sdk/index.html

Since the recent Android website and Google in the domestic often do not go, I put the download to the network disk, there is a need to download: http://pan.baidu.com/s/1hq3iBGw

Prepared files


Installing the NDK environment on a new version of ADT is very convenient, my ADT version is V22.0.5 and the version number is displayed when the ADT is opened for loading


On the official website: http://developer.android.com/tools/sdk/ndk/index.html Download the latest NDK,NDK version integrates Cygwin after R7 and does not need to be installed separately Cygwin

1. Eclipse Configuration


SDK Configuration


NDK configuration, the path is the extracted NDK root directory


Let's test if the NDK is installed successfully.

Create an Android project with add Native support




The new project is now a JNI directory.


An error may be reported by the IDE:

[2014-06-23 17:08:36-unable to launch Cygpath. is Cygwin on the path?] Java.io.IOException:Cannot Run Program "Cygpath": CreateProcess error=2,?? Õ?» µ½?¶

Right-click the project and select the following options



Setting environment variables Ndkroot,value is the NDK directory you extracted.


Configured here: ${ndkroot}/ndk-build.com is the following script file


Then go to the clean project and you won't get an error.


The following is to write the JNI C + + file, but there is no code hint, because there is no reason to import the header file


Import header File method, select "Project Properties"


Click "Add"



At this point, press "ALT +/" to have a code hint


The next step is to write code

In the NDKTest.cpp file

#include <string.h> #include <jni.h>jstring java_com_dzt_ndktest_mainactivity_stringjni (jnienv* env,        jobject thiz) {return Env->newstringutf ("Hello jni my first Jni");}
The Android.mk file is automatically generated and can be used without modification

Local_path: = $ (call My-dir) include $ (clear_vars) local_module    : = ndktestlocal_src_files: = Ndktest.cppinclude $ ( Build_shared_library)
Activity class calling Code

Package Com.dzt.ndktest;import Android.app.activity;import Android.os.bundle;import android.widget.textview;public Class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main); TextView TV = (TextView) Findviewbyid (r.id.tv); Tv.settext (Stringjni ());} Public native String Stringjni (); static {system.loadlibrary ("Ndktest");}}
Build Project


Successfully passed


Run the program again, unfortunately, the error


If the C + + file needs to be added extern "C", export from C language

Modify the code as follows

#include <string.h> #include <jni.h>extern "C" {jstring java_com_dzt_ndktest_mainactivity_stringfromjni ( jnienv* env,jobject thiz) {return Env->newstringutf ("Hello JNI");}}

Successfully passed


Source code Download: http://download.csdn.net/detail/deng0zhaotai/7540771
More examples can be obtained from the following directory, which is an example of the NDK's own.



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.