Reason: java.lang.UnsatisfiedLinkError: unable to load library

I am writing a game, and I have a huge native library, I am trying to load my native library into my main activity, for example

static { try { System.loadLibrary("mylib"); } catch (UnsatisfiedLinkError e) { Log.d(TAG, "Unsatisfied Link error: " + e.toString()); } } 

I tested this code on many devices at home, I am not getting this error. but from my published one I make magazines with " Reason: java.lang.UnsatisfiedLinkError: cannot load library ". NOTE. This failure is not universal, only a few people get this failure.

  • Is this a problem when the library fits in the exported apk? Do I now have the library placed in /libs/armabi/libmylib.so automatically using eclipse?
  • Is this something related to the Android version? I support Android versions with 2.3 (API level 9)
  • or do I need to download the library from another place?
  • or I miss something very important.
  • Problem installing the entire application on sdcard?

Additional information about the failure: load_segments: 68 Could not display the segment from mylib.so

+8
android
source share
1 answer

Considering that your application works correctly on most devices and only occasionally gives you an error, we can safely assume that the library is correctly packed in the APK and that its size / memory size is also acceptable.

As such, I will go on a whim and suppose that the problem is related to the library assembly / compilation architecture. Most newer Android devices use the ARM7 processor. It is very likely that your library is compiled against the ARM7 architecture. Some older devices, especially those running Android 2.3, use an ARM6 processor (I have one such device that I use for testing - the LG GT540 running Android 2.3.3), which does not support transitions with the ARM7 architecture. I saw an error with an error similar to the one you indicated (load_segments: 68 could not display the segment from mylib.so) when I tried to run the application designed for ARM7 on my old ARM6 phone.

There are three ways around this problem:

  • Compile the library from both architectures and include two separate .so files in apk. Then, at runtime, determine the type of processor and load the correct one. Honestly, I do not know if this is possible.

  • Create two separate apk files - one for ARM6 and one for ARM7 - then use the filters in the manifest to specify the appropriate architecture. You can download both of them on Google Play for the same application - and the filters in the manifest will control which one is downloaded to any device.

  • Support the ARM7 architecture by specifying device requirements in the manifest. You will lose some customer audience, but you will have less work to maintain two versions of the application.

EDIT:. According to the NDK documentation, it can create several libraries for different architectures at a time. You can control which processors you want to configure by adding the following line to the Application.mk file:

 APP_ABI := arch1 arch2 arch3 ... 

eg,

 APP_ABI := armeabi armeabi-v7a mips 

Then the build process will create different versions of the native library. These versions should be placed in the latest apk in the directory

 lib/<abi>/lib<name>.so 

where is the name of the architecture. Then you load the library with

 System.loadLibrary("<name>"); 

Alternatively, you can create separate apk files for each architecture, and then use the multi-apk functions in google play.

You can find all the architecture targeting information in the CPU-ARCH-ABIS.html in the docs NDK subdirectory.

+14
source share

All Articles