Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use 32-bit jni libraries on 64-bit android

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)?

like image 451
G B Avatar asked Nov 28 '14 10:11

G B


People also ask

Is 32-bit instead of 64-bit android?

Originally, Android OS was a 32-bit operating system. It required a number of significant updates before the Android OS began working with 64-bit CPUs. Moreover, as recently as in 2021, many games and applications compatible with 32-bit CPUs only were still available on Google Play.

Does Android run 32-bit?

For the unaware, Android currently supports both 32-bit and 64-bit applications. Due to this, developers have to maintain two binaries for their apps and ARM has to offer CPUs that feature legacy 32-bit support.

What is JNI libs in Android?

jni/libs folder is where your shared library files are built from the C/C++ sources. Your native code gets compiled and depending on the value you had set in your application.mk file for the parameter APP_ABI: = <all | x86 | armv7a | armeabi-v7 | mips>


1 Answers

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.

like image 146
G B Avatar answered Sep 24 '22 00:09

G B