After upgrading to 1.3, Android Studio can develop the NDK, but the current support for the NDK is only experimental in nature and may change in the future.
Configuration requirements:
1, Gradle 2.5+;
2, Android NDK r10e;
3. SDK with Build Tools at least version 19.0.0
Try to use the latest version, the current Gradle version is the 2.8,NDK version is the R10e,build tools version is 23.0.2.
Configuration file Modification:
There is no difference between creating a new NDK project and creating a new generic project, and we need to modify the configuration to support NDK development, where it needs to be modified as follows:
Build.gradle modified to support the experimental plugin:
Gradle/wrapper/gradle-wrapper.properties Modification:
App/build.gradle Modification:
For more detailed changes see official website and github, click Sync Gradle after the modification is complete:
At this point, the configuration modification is complete.
Code writing:
1, create a new JNI directory under the app/src/main/java/directory, and then write the C code of the new Hello-jni.c file, or write the native method in the preceding Java class, at which point the Android studio will prompt for no native method, hold down Alt +enter will eject the solution,
Tapping enter again automatically generates the HELLO-JNI.C file and corresponding code for us in the app/src/main/java/jni/directory, which is much more convenient than writing HELLO-JNI.C files manually.
Note that the name of the library in Java code system.loadlibrary ("hello-jni") and the android.ndk {modulename = "inside the App/build.gradle file" hello-jni"} name to unify, otherwise will error java.lang.UnsatisfiedLinkError.
2. Call the native method in Java:
3, the operation can see the effect:
Developing the NDK using Android Studio