可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Is there someone who had experience with this error?
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.swig.simple-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "liborg.swig.simple.example.so"
Error occurs when I load library by this way.
static { System.loadLibrary("example"); }
I'm sure 'example' class is exist in the current folder.
回答1:
Please note that there's a naming convention. Your lib needs to be called libexample.so .
LoadLibrary("example") will look for libexample.so.
The .so library needs to be inside the apk under the lib folder (since you are developing for Android, it needs to be under the lib/armeabi and lib/armeabi-v7a folders - why both folders ? some versions of Android look under lib/armeabi and some look under lib/armeabi-v7a ... se what works for you ).
Other things to look for :
make sure you compile for the correct architecture (if you compile for armeabi v5 it won't work on armeabiv7 or armeabiv7s ).
make sure your exported prototypes are used in the correct class (check the hello jni example. Your exposed functions need to look something like Java_mypackagename_myjavabridgeclass_myfunction).
For example the function Java_com_example_sample_hello will translate in the java class com.example.sample , function hello.
回答2:
This helped me. Sharing it for someone who might come up with same issue.
android { .... defaultConfig { .... ndk { abiFilters "armeabi", "armeabi-v7a", "x86", "mips" } } }
回答3:
What worked for me was to place the jniLibs folder under the "main" folder, just besides the "java" and "res" folders, for example project -> app -> src -> main -> jniLibs
I had all the libraries with the correct names and each one placed on their respective architecture subfolder, but I still had the same exception; even tried a lot of other SO answers like the accepted answer here, compiling a JAR with the .so libs, other placing of the jniLibs folder, etc.
For this project, I had to use Gradle 2.2 and Android Plugin 1.1.0 on Android Studio 1.5.1
回答4:
Some old gradle tools cannot copy .so files into build folder by somehow, manually copying these files into build folder as below can solve the problem:
build/intermediates/rs/{build config}/{support architecture}/
build config: beta/production/sit/uat
support architecture: armeabi/armeabi-v7a/mips/x86
回答5:
I am currently working on an android application which streams radio. I use native decoder library which is called aacdecoder. Everything was fine till app gets crash error on some android devices. It was really annoying. Because app was perfectly plays radio streams almost all devices but Samsung S6 and S6 Edge.
Crash report says that
Fatal Exception: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/com.radyoland.android-1/base.apk”],nativeLibraryDirectories=[/data/app/com.radyoland.android-1/lib/arm64, /vendor/lib64, /system/lib64]]] couldn’t find “libaacdecoder.so” at java.lang.Runtime.loadLibrary(Runtime.java:366) at java.lang.System.loadLibrary(System.java:988) at com.spoledge.aacdecoder.Decoder.loadLibrary(Decoder.java:187)
As you see that crash is saying that it could not load native library. But why? First of all I checked my structure, If native library .so files located correctly.
Seems everything was okay except this crazy error. Then after some research, I find out that some of android devices has 64-bit processors. This devices generates and check arm64 folder to load native library. That was the problem. Because my project does not have arm64 folder. Here is the solution;
defaultConfig { ... ndk { abiFilters "armeabi-v7a", "x86", "armeabi", "mips" } }
You need to add this filters(abiFilters) to your app module’s build.gradle files. So when your device try to run your app, it will check gradle file and understands that it should not generate any folder and use existing native library resources. Boom. Almost solved. But still there is one more thing.
android.useDeprecatedNdk=true
Add this line to your gradle.properties to use deprecated Ndk.
Finally my app works on S6 and S6 Edge. I mean It works on every devices which has new 64-bit processors. It's a late answer but I hope this will help some one like me.
回答6:
This is worked for me
If your having .so file in armeabi then mention inside ndk that folder alone.
defaultConfig { applicationId "com.xxx.yyy" minSdkVersion 17 targetSdkVersion 26 versionCode 1 versionName "1.0" renderscriptTargetApi 26 renderscriptSupportModeEnabled true ndk { abiFilters "armeabi" } }
and then use this
android.useDeprecatedNdk=true;
in gradle.properties file
回答7:
I use Android Studio 3.0 and encounter this problem. And I'm sure app's build.gradle is OK.
Go to Run -> Edit Configurations -> Profiling, and disable "Enable advanced profiling".
This works for me. Reference answer
回答8:
If you use module with c++ code and have the same issue you could try
Build -> Refresh Linked C++ Projects
Also, you should open some file from this module and do
Build -> Make module "YourNativeLibModuleName"
回答9:
System.loadLibrary
loads a shared library from lib
folder.
What do you mean when saying "I'm sure 'example' class is exist in the current folder"? You should put your .so library to lib
folder.
回答10:
For me the problem was in NDK_ROOT not being set.
Check your console if:
NDK_ROOT = None [!] NDK_ROOT not defined. Please define NDK_ROOT in your environment or in local.properties
Check if you have set:
- NDK_ROOT and SDK_ROOT in C/C++->Build->Environment
- Android->NDK
- Android->SDK
回答11:
This could be device related issue.
I was getting this error in MI devices only, code was working with all other devices.
This might help:
defaultConfig{ ... externalNativeBuild { cmake { cppFlags "-frtti -fexceptions" } } }
回答12:
If you are using Android studio, just edit the gradle.properties in the root folder and add android.useDeprecatedNdk=true. Then edit the build.gradle file in your app's folder, set abiFilters as below:
android { .... defaultConfig { .... ndk { abiFilters "armeabi", "armeabi-v7a", "x86", "mips" } } }
回答13:
-if gradle.properties not available then first add that file and add android.useDeprecatedNdk=true
-use this code in build.gradle
defaultConfig { applicationId 'com.example.application' minSdkVersion 16 targetSdkVersion 21 versionCode 11 versionName "1.1" ndk { abiFilters "armeabi" } }
`