Recently I was working on some projects where the native library (*.so) is used. It builds in Android Studio without any problem, but when I run it on the Android devices, it crashes with the following error message:
Can’t load xxx library: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file “/data/app/some.package.name/abc.apk“],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn’t find “abcxyz.so“
After millions of trial and error, here comes the solution:
- Create a folder called “lib” (must be exactly this name)
- Create subfolders in lib with desired architecture name such as “armeabi-v7a”, “armeabi” etc.
- Put all your *.so file in the just created folder
- Now your folder structure should be like this:
- Zip the lib folder into a file, e.g. abc.zip;
- Rename this abc.zip –> abc.jar
- Copy this abc.jar to your project subfolder, anywhere should do, but I would typically put it in the app\libs\abc,jar
- In the build.gradle, add:
Rebuild, that is all! Happy Coding!