31

I've tried running an application using a native library on the Nexus 9.

The application exits with an error message:

java.lang.UnsatisfiedLinkError: dlopen failed: "lib_xyz.so" is 32-bit instead of 64-bit

Is there any known workaround for this problem (except, of course, recompiling the library and making the apk bigger)?

7 Answers 7

34

Found an explanation: 64-bit Android can use 32-bit native libraries as a fallback, only if System.loadlLibrary() can't find anything better in the default search path. You get an UnsatisfiedLinkError if you force the system to load the 32-bit library using System.load() with the full library path. So the first workaround is using System.loadLibrary() instead of System.load().

An additional thing that has to be taken into account is that libraries cannot be mixed: the fallback behaviour only applies for the first library your application loads. If the first one is 64-bit, no 32-bit libraries can be loaded by the same application, and vice versa.

8
  • Hey G B, is there a source for that?
    – orospakr
    Apr 9, 2015 at 18:40
  • Yes. I`ve discovered it by browsing the Android source code (how library loading is implemented)
    – G B
    Apr 10, 2015 at 9:08
  • 1
    @gb I know this is maybe old stuff, but we're finding that after an OS upgrade to Android 5.1.1 on a Galaxy S6 Edge this is not working anymore. Before that it was working. Do you know if this has changed? Can you point out where you found this? Thanks! Sep 10, 2015 at 14:55
  • 2
    Nevermind, the reason was other (and something to remember to check in this cases): we added a module to our project which had a dependency to a JNI library. This library has support for 64 bits, and the compatibility fallback gets disabled in this cases. Sep 13, 2015 at 11:50
  • 1
    How to solve this crash? Any code solution for this issue? Jan 24, 2019 at 19:19
19

the point is to convert the run environment to 32 bit

  1. add the follow content in build.gradle

    defaultConfig: { ... ndk { abiFilters "armeabi", "armeabi-v7a", "x86", "mips" } }

  2. add android.useDeprecatedNdk=true into gradle.properties

  3. add new folder named armeabi under the libs, then copy a 32bit .so file into the new folder
7
  • What if I am using CMake instead of NDK builds? How do I use defaultConfig': ndk {abiFilters "armeabi", "armeabi-v7a", "x86", "mips" } and android.useDeprecatedNdk=true.
    – savi
    Feb 28, 2018 at 21:59
  • 1
    This was enough for me to stop the crash from happening ndk { abiFilters "armeabi-v7a", "x86" } Mar 2, 2018 at 12:42
  • 2
    From where i can download 32bit .so file? Feb 12, 2019 at 15:55
  • 2
    Will Android block workaround this after Aug '19 as a full 64 bit requirement ? Mar 29, 2019 at 11:48
  • 4
    From august 1 2019 we have to follow 64 bit guideline as stated in google policy. By doing the above steps play store shows a warning
    – Tarun
    Jul 12, 2019 at 7:27
4

This work for me:

 ndk {
        abiFilters 'armeabi-v7a', 'x86'
    }
4
  • 1
    ooh you are life saver buddy :) Thank you so much
    – iamkdblue
    May 1, 2020 at 21:36
  • This worked for me : ndk { abiFilters "armeabi", "armeabi-v7a", "x86", "mips" }
    – Nabzi
    Dec 13, 2020 at 12:32
  • 1
    This works but remember that when you upload your .apk or App bundle, Google Play Store will force you to support 64-bit architecture and you will be forced to add back variants to abiFilters and the problem will also come back
    – Antares
    Feb 23, 2021 at 11:29
  • So what is the solution for this need to upload playstore.
    – Mani
    Apr 29, 2021 at 7:03
1

https://source.android.com/source/64-bit-builds.html

Try this in you Android.mk

LOCAL_MULTILIB := 32
0

Nop, you need to get the native library to be compatible with 64-bit for it to work.

See official documentation: JNI Tips: 64-bit Considerations

2
  • Actually, it doesn't say anything like that: "For the most part this isn't something that you will need to worry about when interacting with native code". After reading that paragraph, an UnsatisfiedLinkError is the last thing I'd expect.
    – G B
    Nov 28, 2014 at 13:38
  • You might be right, but I think UnsatisfiedLinkError happened to me when I had your exact some problem once. I might be wrong, sorry if that's the case. Hope someone will help you out more. Nov 28, 2014 at 13:41
0

I encountered the same issue, when I did the update from Android Studio 2.1 to 2.2.3 (with ndk v.13.1), and no tips found in google really helped me (like using abiFilters, exclude 'lib/x86_64/lib….so’, LOCAL_MULTILIB := 32, or TARGET_PREFER_32_BIT := true, …).

Finally, I was able to make it worked again with the latest AS v2.2.3 (without changing anything in Android.mk or in build.gradle), just by using my previous ndk compiler, i.e. android-ndk-r10e

I built the library manually with ndk-build for "armeabi-v7a" and "x86" only, and it worked like a charm on Android with arm64.

0

For me the problem was that I enabled the advanced profiling feature under the build settings of the app

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.