1

I am loading my native library by:

try {
       System.loadLibrary("myNative");
} catch (UnsatisfiedLinkError e) {
       //java.lang.UnsatisfiedLinkError here
       System.load("/data/data/com.my.app/my_native/libmyNative.so");
}

The above code works fine on other devices except Android 5.0 Lollipop. When run on Android 5.0 Lollipop device, I constantly get the following error:

java.lang.UnsatisfiedLinkError: dlopen failed: "/data/data/com.my.app/my_native/libmyNative.so" is 32-bit instead of 64-bit
at java.lang.Runtime.load(Runtime.java:331)
at java.lang.System.load(System.java:982)

How to solve this problem?

=== UPDATE ====

I copied the native library from lib/<archType>/libmyNative.so to /data/data/com.my.app/my_native/libmyNative.so and then use the above code to load the library.

Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • Nexus 9? What device are you using? Your error is here: `is 32-bit instead of 64-bit`. Compile against the 64 bit libs. – Jared Burrows Mar 11 '15 at 16:47
  • Yes, Nexus 9. I know where the error is. But I am seeking for a way to make it work with 32-bit native library. – Leem.fin Mar 11 '15 at 16:54
  • Is this a normal third party app installed via an APK, or is it preinstalled in a ROM? In the former case, the process should be started in the right mode (32/64 bit) depending on what flavor of native libraries you have included in the package. In the latter case, have a look at http://stackoverflow.com/questions/27712921/how-to-use-32bit-native-libraries-on-64-bit-android-l-platform/27713998#27713998. – mstorsjo Mar 11 '15 at 17:04
  • @mstorsjo, neither. It is my own native code , ndk-built & used(load) in my own app. – Leem.fin Mar 11 '15 at 17:07
  • Then the app process should be launched in 32 bit mode just fine - apps built with old NDK versions should still work just fine. Can you add a listing of what e.g. "unzip -l yourapp.apk" shows? – mstorsjo Mar 11 '15 at 17:08
  • How do you build your native lib? Try to run `ndk-build APP_ABI=armeabi`. – Alex Cohn Mar 11 '15 at 19:35
  • The first call (`System.loadLibrary("myNative");`) has to work. Please give us the actual exception it throws, and also the list of libs you have inside your APK. – ph0b Mar 12 '15 at 17:54
  • @Leem.fin Have you resolved this? – Jared Burrows Apr 04 '15 at 14:26
  • @JaredBurrows - mstorsjo's answer explained what was being done wrong over a month ago. – Chris Stratton Apr 06 '15 at 14:50
  • @Leem.fin Can you post your solution as an answer? – Jared Burrows Apr 06 '15 at 14:56

1 Answers1

2

It seems that some part of the way of packaging your libs (copying them from lib/<archType>/libmyNative.so to /data/data/com.my.app/my_native/libmyNative.so) confuses the installer. When installing an APK, it should already automatically extract the libraries of the right arch type and have them available to System.loadLibrary - you shouldn't need to copy anything manually into a custom directory like my_native.

Is <archType> in this case one of the existing (armeabi, armeabi-v7a, etc) or something of your own? If it isn't one of the standard ones, the installer won't know that your app contains 32 bit native code, and thus will launch your app's process in the preferred mode (64 bit).

mstorsjo
  • 12,983
  • 2
  • 39
  • 62