Clean up Eclipse's NDK development and then organize your Android studio.
A relatively good Baidu network disk: http://pan.baidu.com/share/home?uk=2383159761 often update the latest Android development package, you can download to the NDK package
Create an Android project, put a textview for displaying text, function is simple, get the string from the native layer and display it on the TextView
Then write the relevant code:
Public classMainactivityextendsappcompatactivity{//Load so Static{system.loadlibrary ("Myjni"); } //declaring a local method Public nativeString GetString (); @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); TextView TextView=(TextView) Findviewbyid (R.ID.TEXTVIEWID); Textview.settext (GetString ()); }}
1. Select the menu build-->build APK and use command line cmd to enter the Android project \app\src\main\java directory to generate the. h header File
Javah-d. /JNI package name. Main Activit Name
such as: javah-d. /jni Com.example.eclipsendk.MainActivit
2. In the Project Catalog column Jni folder right----C/c++source File
Fill in the file name, select the. C file (do not generate a header file), and if you use a. cpp file, remember the extern "C"
3. Write the native layer code, in MyJni.cpp
#include"Test_com_androidstudiondk_mainactivity.h"//Copy the function declaration from the file.jniexport jstring jnicall java_test_com_androidstudiondk_mainactivity_getstring (JNIEnv*env, Jobject obj) { //. c files are used in this way return(*env)->newstringutf (env,"Hello Android Studio NDK"); //. cpp files are used in this way//return Env->->newstringutf ("Hello Android Studio NDK");}
4. Then add the contents of several files
①. local.properties file, adding the path to the NDK
②. gradle.properties file declaration using the NDK
Android.usedeprecatedndk=true
③. The name of the Build.gradle file in the app directory.
You can toggle the view from here
④. After the changes are complete, compile the apk and put it into the emulator to run.
Debug version (Build APK) generated in: app\build\outputs\apk directory
Release version (Generate signed APK) generated in: App Directory
Android Studio NDK Development