Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android multidex, UnsatisfiedLinkError - couldn't find .so file

i'm trying to add some lib (.jar & .so)to my multidex project in android studio.

when i add only a few jars to the project everything works fine. in case i add more and more jars (other libs) i'm getting this error:

java.lang.UnsatisfiedLinkError:
  dalvik.system.PathClassLoader[DexPathList[[zip file
  "/data/app/com.test.digital.ocrtest-2/base.apk"],nativeLibraryDirectories=[/data/app/com.test.digital.ocrtest-2/lib/arm,
  /data/app/com.test.digital.ocrtest-2/base.apk!/lib/armeabi-v7a,
  /vendor/lib, /system/lib]]] couldn't find
  "libScanovatePassportAndIDLSDK_CPP.so"

any idea how can I tell to the compiler to generate jar and so in same dex?

like image 554
Nimrod Borochov Avatar asked Nov 30 '15 16:11

Nimrod Borochov


2 Answers

If some of the extra JARs bring native libraries for armeabi-v7a, while your libScanovatePassportAndIDLSDK_CPP.so was only built for armeabi, the installer will extract a wrong set of libraries. The fix is not to add more copies of .so, but rather strip away the other ABIs. In gradle, you can use splits.

like image 163
Alex Cohn Avatar answered Oct 31 '22 16:10

Alex Cohn


There is an elegant solution for this. When your APK file doesn't contain all native libs in 64bit version for a certain ABI you just need to make sure that your APK file does not contain any 64bit libs. Here is the tutorial on how to configure your project to fix this: https://corbt.com/posts/2015/09/18/mixing-32-and-64bit-dependencies-in-android.html

Background When your app is installed on 64bit ABI devices, package manager scans the APK file on install and looks for 64bit native libraries. If it finds the appropriate 64bit native library folder (you can check /libs folder in your APK file if you open it with any zip client) it assumes that all native libraries are available in 64bit versions. If one or more native libraries are not available in 64bit version, the package manager will fail to load their 32bit version. Hence, when the app attempts to run code that relies on these native librairies you will get this UnsatisfiedLinkError message. This means that the 32bit version of your library

like image 34
Simon-Droid Avatar answered Oct 31 '22 16:10

Simon-Droid