Android Studio uses JNI, so libraries
After Android Studio1.1, as has already supported the JNI and so library, immediately released the 1.3 official version, but also can be compiled in the clion environment C, C + +, more convenient to use the NDK for development, online there are many speaking on Android The method of using JNI in studio, but mostly before 1.1, did not directly support JNI at that time, so it was necessary to add support by adding a task to gradle. And now, all this is not a thing!!!
Add Lib Library
Switch to the Project tab and copy the jar package directly to the Libs directory and add the dependency.
Add So Library
There are two ways to add an so library. but it is highly recommended to use a simple and rude way.
Simple Rough
In the main directory right click, add folder, named jnilibs, you need to note that a word can not be wrong, this is the default name.
Custom Catalog
Under Main you can customize a directory, for example: XYs. Then, under Build.gradle's Android tab, add the following modifications:
sourceSets { main { jniLibs.srcDirs = [‘xys‘] } }
Specify a specific directory for the next jnilibs.
Use
In the code, you only need to:
static { System.loadLibrary("XXXX"); }
and specify the method that corresponds to the native:
publicstaticnativevoidnativeXXXXX();
These should not be talked about.
Warning
There are several places to be aware of when using JNI.
Package Name
In the LoadLibrary program, the package name must be the same as the package name of so library.
So library version
Under Jnilibs, it is best to place:
It's best to have a few versions, but in fact, it's enough to put a armeabi-v7a. But when things go wrong, be sure to go to this place and think.
Android Studio uses JNI, so libraries