61

I use a native library in my application that is only compiled for armeabi, armeabi-v7a and x86.

When this library is loaded on a 64-bit device like the Samsung S6, the application crashes with an UnsatisfiedLinkError

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.myapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libfoo.so"
    at java.lang.Runtime.loadLibrary(Runtime.java:366)
    at java.lang.System.loadLibrary(System.java:989)

The library is closed source unfortunately. Is there any way to fix this without recompiling the library with 64-bit targets?

4

2 Answers 2

149
+50

When you install an APK on Android, the system will look for native libraries directories (armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips64, mips) inside the lib folder of the APK, in the order determined by Build.SUPPORTED_ABIS.

If your app happen to have an arm64-v8a directory with missing libs, the missing libs will not be installed from another directory, the libs aren't mixed. That means you have to provide the full set of your libraries for each architecture.

So, to solve your issue, you can remove your 64-bit libs from your build, or set abiFilters to package only 32-bit architectures:

android {
    ....
    defaultConfig {
        ....
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
        }
    }
}
10
  • 1
    Looks good, the 64-bit folders are gone with this snippet. I will mark the answer as accepted once I can find a 64 bit phone to reproduce
    – Philipp E.
    Jun 12, 2015 at 15:32
  • Getting error NDK integration is deprecated in the current plugin. Consider trying the new experimental plugin. Nov 25, 2015 at 12:49
  • 12
    add android.useDeprecatedNdk=true to a file named gradle.properties at the root of your project. btw don't feel bad about using a deprecated integration, as using abiFilters is still the cleanest way atm to filter out 64-bit libs from an APK.
    – ph0b
    Nov 30, 2015 at 18:05
  • 4
    As of today (August 1st, 2019), you cannot submit APKs to the Google Play Store without 64-bit architecture. Aug 1, 2019 at 16:47
8

The above answer will help to generate a build with 32- bit only not a 64-bit. If you are using [ abiFilters "armeabi", "armeabi-v7a", "x86", "mips" ]. generate signed apk means, that is not for 64 bit. It will raise an error when we upload into Google Play store. It is not an 64 bit build.

Your Answer

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

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