Android Studio uses the jni and so libraries and androidjni
Android Studio uses the jni and so Libraries
After Android Studio1.1, AS has already supported the jni and so libraries. The official version 1.3 is now released. It can compile c and c ++ in the clion environment, it is more convenient to use NDK for development. There are many examples on the Internet that use jni in Android Studio, but most of them were earlier than 1.1. At that time, jni was not directly supported, therefore, you need to add support by adding tasks to gradle. Now, this is not a thing !!!
Add lib Library
Switch to the project tag, copy the jar package to the libs directory, and add the dependency.
Add so Library
There are two methods to add the so library.However, we strongly recommend that you use a simple and crude method.
Simple and crude
Right-click the main directory and add a folder namedJniLibsNote that a word cannot be wrong. This is the default name.
Custom directory
In main, you can customize a directory, for example, xys. Add the following changes under the Android tag of build. gradle:
sourceSets { main { jniLibs.srcDirs = ['xys'] } }
Specify the directory of jniLibs.
Use
In the code, you only need:
static { System.loadLibrary("XXXX"); }
And specify the native method:
public static native void nativeXXXXX();
This should be skipped.
Warning
When using jni, there are several points worth attention.
Package name
The program in loadLibrary, package nameMust be the same as the so library package name.
So library version
In jniLibs, it is best to place:
It's best to have a few of these versions, but in fact, it's enough to put a armeabi-v7a. But when an error occurs, you must think about it in this place.