1, write Java code, specify the Lib and native methods.
Package com.taven.myapplication;
Package com.taven.myapplication;
Import android.support.v7.app.AppCompatActivity;
Import Android.os.Bundle;
public class Mainactivity extends Appcompatactivity {
static {
System.loadlibrary ("jni-lib-1");
}
Private native void Sayhellojni ();
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (Savedinstancestate)
Setcontentview (R.layout.activity_main);
}
}
2. Create a new JNI folder and create a new android.mk file in the Jni folder
The contents of the Mk file are as follows:
#指定编译的文件夹 Specify the current file directory
Local_path: = $ (call My-dir)
#编译器会定义很多的临时变量, intermediate variables, preferably emptying all intermediate variables.
Include $ (clear_vars)
#编译器编译出来的模块名称
local_module:= jni-lib-1
#编译器编译出来的源代码的名称
local_src_files:= jni-lib-1.c
#编译一个动态库, Static Library
#静态库 file name. A contains all of the functions and the function is dependent on the run, large size, including all the APIs
#动态库 file name. So contains functions that do not contain the dependencies of function runs, small size, and when running, go to the operating system to find the required API
Include $ (build_shared_library)
3. Add the Mk file path under the Build.gradle of the app
Externalnativebuild {
Ndkbuild {
Path file ("Src\\main\\jni\\android.mk")
}
}
4, you can add the exclusion option, specify to generate the specified platform so file.
Add the following code to the Defaultconfig in the Android node in the App->build.gradle file:
NDK {
Abifilters "Armeabi", "armeabi-v7a", "x86"
}
5, regenerate the project (Rebuild), when the mouse is placed on the native method, the generation of JNI code hints will appear. The Jni file is automatically generated by pressing Alt+enter.
6. Fill in the C code
7, compile the project again, the resulting so library directory in the app/build/intermedieates/ndkbuild/debug/obj/local/directory;
8, the operation can be.
Androidstudio 2.3.3 JNI Process Rollup (1): 1, write your own C file and use (original)