Some errors and methods used by JNI in Android Studio

Error 1
Error: NDK integration is deprecated in the current plugin.
Add android.useDeprecatedNdk=true in the gradle.properties file and then recompile.
Error
2 Native method not found: The so file in libs is not recognized, JNI finds it No method
added : jniLibs.srcDirs = ['libs']
Error 3
Native method not found: The so file inside is not recognized, JNI cannot find the method
So file location is wrong, put it in the armeabi-v7a folder, Don't put it in armeabi
Error
4 android studio packs the so file into apk
.so has been put under libs\armeabi and you can see from the packaged apk that the .so has been packaged (decompress the apk file, there should be a corresponding file in the lib file .so file) But after installing the apk, there is no corresponding .so file in the mobile phone path /data/data/com.test.test/lib
Because my .so is not named according to the android standard, the name of .so must have 'lib' prefix otherwise the .so under libs\armeabi will not be copied to /data/data/com.test.test/lib when the apk is decompressed/installed on the phone. For example, the so name I used was JNITest.so, and everything was normal after changing it to libJNITest.so.
When calling with loadLibrary, you need to remove the lib prefix System.loadLibrary(“JNITest”);
when calling with load, you need to write the full path name and cannot remove the lib prefix because this is System.load(“/data” which is read as a normal file /data/com.test.test/libJNITest.so");

Error 5
The difference between armeabi v7a and armeabi
armeabi is for ordinary or old arm cpu, armeabi-v7a is for arm cpu with floating point operation or advanced extended functions.
Android from 2.2 supports armeabi-v7a
early Cortex-A series processors (A5, A7, A8, A9, A12, A15 and A17) based on ARMv7-A architecture.
Qualcomm 820 quad-core ARMv8
Samsung Exynos 8890 ARM Cortex-A53
Kirin 950 quad-core A72+ quad-core A53
compatible and file reading order
arm64-v8a is backward compatible, there are armeabi-v7a, armeabi, armeabi-v7a down Compatibility with armeabi is not smart enough: for a mobile phone whose cpu is arm64-v8a architecture, when it runs the app, when it enters jnilibs to read the library file, first see if there is an arm64-v8a folder: if there is no such folder, look for it If there is no armeabi-v7a folder, then go to the armeabi folder. If there is no such folder, an exception will be thrown. If there is an arm64-v8a folder, then go to the .so file with a specific name. Note: If it is not found, it will not look further down (armeabi-v7a folder), but throw an exception directly.
At the same time, in order to avoid the so file of arm64-v8a in the referenced third-party library, the 64-bit machine is still changed from arm64- The v8a folder reads the so file and filters out all the so files that are not armeabi-v7a: add ndk .abiFilters

 defaultConfig {
        applicationId "xx.xx.x.xx"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 15
        versionName "1.2.7"
        multiDexEnabled true
        ndk {
            abiFilters  "armeabi-v7a"  // 指定要ndk需要兼容的架构(这样其他依赖包里mips,x86,armeabi,arm-v8之类的so会被过滤掉)
        }
    }

Error 6
If you have packaged the .so and .a files (dynamic and static libraries) into the apk, but it still says that the jni method cannot be found,
then create the armeabi-v7a folder under the libs folder, and put libg**** Put the .so file and lib****.a file in this directory, and change the .so file in the armeabi folder to another place

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325473610&siteId=291194637