Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use 32-bit native libraries on 64-bit Android device

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?

like image 878
Philipp E. Avatar asked Jun 11 '15 13:06

Philipp E.


People also ask

Can a 64-bit application use a 32-bit library?

On 64-bit Windows, a 64-bit process cannot load a 32-bit dynamic-link library (DLL). Additionally, a 32-bit process cannot load a 64-bit DLL.

How can I tell if APK is 32 or 64-bit?

APK is ZIP. You can open it and check directory lib to see which architectures are supported. If there is no directory lib , it supports all architectures. 64-bit Android is backwards compatible and can run 32-bit applications.

What is ARM64 v8a in Android?

arm64-v8a. This ABI is for ARMv8-A based CPUs, which support the 64-bit AArch64 architecture. It includes the Advanced SIMD (Neon) architecture extensions. You can use Neon intrinsics in C and C++ code to take advantage of the Advanced SIMD extension.


1 Answers

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"         }     } } 
like image 154
ph0b Avatar answered Sep 24 '22 05:09

ph0b