Gossip does not say much, direct into the topic:
My environment:
Operating system: OSX 10.10
Ide:eclipse Luna
Sdk:19
By default you've set up the SDK development environment
The first step is to download the NDK Toolkit under the OSX platform:
Compare the new R10 version in My network to download: Http://pan.baidu.com/s/1eQhn9aq
Second step, configure the environment variables
Create the. bash_profile file under your user directory to add:
Export path=${path}:/users/devnn/documents/android_ndk/android-ndk-r10ea_ndk_root=/users/devnn/documents/ Android_ndk/android-ndk-r10eexport A_ndk_rootexport path=${path}:/users/devnn/documents/android-sdk-macosx/ Platform-toolsexport path=${path}:/users/devnn/documents/android-sdk-macosx/toolsa_sdk_root=/users/devnn/ Documents/android-sdk-macosxexport A_sdk_root
Of course, note that the path should be modified accordingly.
Step three, open Eclipse config ndk path, preference->android->ndk
Fourth step, create test engineering ndk_test
Fifth step, right-click Project->android tools->add Support Library
Then create a directory in your project directory JNI contains a CPP file and a Mk file. We test the C file first, so we change its suffix to c. The content reference is as follows:
#include <string.h> #include <jni.h>jstring java_com_example_ndk_mainactivity_hello (jnienv* env, Jobject Thiz) {return (*env)->newstringutf (env, "Hello, this was from JNI");}
Note the name of the C file and the corresponding name in the Mk file should be the same.
Here, the C file code will error, see the next step.
Sixth step, right-click Project->propertiers->c/c++ gerneral->paths and Symbols
Click Add under the Include option, a dialog will pop up to let you select the header file path and choose File system, for example, my
/users/devnn/documents/android_ndk/android-ndk-r10e/platforms/android-19/arch-arm/usr/include
At this time, the errors in the C file will disappear.
package com.example.ndk;import android.app.activity;import android.os.bundle;import android.widget.textview;public class mainactivity extends activity { private textview tvtext; @ Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview (R.layout.activity_main); tvtext= (TextView) findviewbyid (R.id.text); tvtext.settext ( Hello ()); } public native string hello (); static{ system.loadlibrary ("NDK_TEST"); }}
My engineering structure is as follows:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/76/20/wKioL1ZK8snSMFgdAADNndiybRk055.png "title=" screen shot 2015-11-17 pm 5.24.16.png "alt=" Wkiol1zk8snsmfgdaadnndiybrk055.png "/>
Then, run your project and you'll see the results.
This article is from the "focus_000" blog, make sure to keep this source http://120806872.blog.51cto.com/8289253/1713581
Build Android NDK development environment under OSX system