Implementing NDK Development in Android Studio is a lot easier than the previous eclipse+cygwin.
This article takes the simplest of strings from a C program and shows the basic flow of NDK development as an example on the TextView of Mainactivity.
Get ready
NDK Development environment
On the installed Android studio, download and install the NDK in SDK Manager or go directly to https://developer.android.com/ndk/downloads/ index.html download the corresponding installation package and unzip it to the ndk-bundle of the SDK.
Setting the relevant environment variables, it is recommended to add tools such as ANDROID-V7, V4 and so on to the environment variables.
Implementation steps
Create Project
Create a directory named JNI under the app (click: New Folder Jni-folder)
Added in gradle_properties file: android.usedeprecatedndk=true
Create a class Ndkutil, in which you declare the native method
public class Ndkuitls {
Public native String getclanguagestring ();
}
Use the command line in terminal, under App\build\intermediates\classes\debug, use Javah-jni lab.example.ndkutil[according to the actual situation]. A. h file is generated next to the directory, and after the file is opened, the contents of it are copied.
Create a new JNI directory (new folder Jni-folder) in the app directory and a C file to paste the contents of. H. and make the corresponding changes.
In the Build.gradle of the App module directory, locate the defaultconfig of the Gradle file and add the NDK configuration information
ndk{
ModuleName "Yourjnilibname"
Abifilters "Armeabi", "armeabi-v7a", "x86"
}
In code ndkutil, load to the class library Yournilibname:
static{
System.loadlibrary ("Yourjnilibname");
}
Compile, run:
Exploring the NDK for Android Studio