Michiyo
Michiyo

Reputation: 1201

Loading android library

I have a library loaded like this:

  static {
    System.loadLibrary("myLibrary");
  }

This works fine on most devices. On one device, however, it causes a crash with this stacktrace:

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/vendor/overlay/myBuild.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "myLibrary.so"
 at java.lang.Runtime.loadLibrary(Runtime.java:366)
 at java.lang.System.loadLibrary(System.java:989)
 at com.sony.foo.bar.<clinit>(myClass.java:20)

The accepted answer here prompted me to try adding a copy of myLibrary to a new armeabi-v7 folder, where the original library was in a folder named armeabi. This fixed the crash.

I am trying to make sense out of this. Does this mean the crashing phone has a different CPU? A CPU-identifier app identifies it as having the same type (maker, model) as the others. Even supposing the crashing phone is armeabi-v7, the most upvoted answer here and the accepted answers here and here make it sound like an armeabi-v7 phone should be able to use the library in the armeabi folder. Is this not the case?

Lastly, is there some better approach to this fix so that I don't have two identical copies of the same library in the apk?

Upvotes: 1

Views: 1092

Answers (2)

Michiyo
Michiyo

Reputation: 1201

This turned out to be caused by having another version of the app installed on the phone in /system/priv-app. Removing that one prevented the crash.

Upvotes: 1

alijandro
alijandro

Reputation: 12167

Firstly, there is no such name armeabi-v7 in Android, the correct name is armeabi-v7a.

The libraries under armeabi-v7a and armeabi is not identical actually. If you add more values to APP_ABI in the file Application.mk as following

APP_ABI := armeabi armeabi-v7a mips x86

After ndk-build, there are four types of libraries will be generated in the folder libs/armeabi, libs/armeabi-v7a, libs/x86, libs/mips. By comparing the files between in libs/armeabi and libs/armeabi-v7a, you will see they are not identical. So far, i can't tell their differences. These two libraries are slightly different in size, so i think there are no big differences between them.

In order to make your app widely supported on most of the Android devices, you better add armeabi-v7a support and keep armeabi-v7a directory.

If you are sure what you are doing, only keep armeabi. Then, you can put your library under assets directory, when your app start and run, you should read your library from assets and load with System.load() manually other than relying on framework package manager system to inflate your library to your app's data directory when you app get installed.

Upvotes: 1

Related Questions