Do not know why the NDK development of the Android data on the Internet very little, and some of the information is basically unable to complete the introductory learning demo, simply can not run, the younger brother spent three days and three nights to get HelloWorld, the degree of insomnia.
The first was to configure the NDK to develop the Magic mirror on Android studio, then the development of Hello World, but Android studio support NDK Development relatively late, no elipse mature, at compile time encountered many problems, Finally give up (I know it's not a good habit, but I'll come back later)
Note: The NDK configuration on the Gradle
Http://gradle.org/getting-started-android/#buildauthor
http://ph0b.com/android-studio-gradle-and-ndk-integration/
Here's a nagging remark, using Android Studio, then it is necessary to strengthen the understanding of gradle.
Start the NDK development on eclipse:
Brief introduction 1. Create an empty Android project
2. Write a local class that defines an empty local method. such as public static native String getstr ();
3. Switch to Project SRC directory, mine is HOME/DLZH/WORKSPACE/HELLONDK/SRC, then execute Javah-jni com.example.hellondk.GetString, then generate an. h file in this directory
4. HELLONDK.C file Write Implementation native method
5. Load so file, run.
The detailed steps are as follows:
1. Create an empty Android project
2. Write a local Getstring.class
public class GetString {//Local code implementation public static native String getstr ();//define local method, implemented by C language}
3. Right-click on the project name and select "Build Project", the JNI and Libs folder will be automatically generated under the project, then right click on the project and select Android tools--"add native support.
4. Then Ubuntu switches to the project's SRC directory, executes the javah-jni com.example.hellondk.GetString command, and returns. Copy the generated com_example_hellondk_getstring.h to the Jni file plus
5. Open the Hellondk.c file under the Jni folder to implement the header file Life method
#include <jni.h> #include <com_example_hellondk_getstring.h>/* * Implement header File Method */jniexport jstring Jnicall Java_ Com_example_hellondk_getstring_getstr (jnienv *env, Jclass) {return Env->newstringutf ("static method call Hello NDK! ");}
Then add the following code under Getstring.java to load the so file
Static{system.loadlibrary ("Hellondk");}
6. Then
public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); TextView TV = (TextView) Findviewbyid (R.id.textview); Tv.settext (Getstring.getstr ());}}
7. Run
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android NDK Development Hello World Introduction