Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use 32bit native libraries on 64 bit Android-L platform

I have a Android application which i compiled with AOSP(Kitkat) as android system application and it was running fine. My application is dependent on native code compiled with Android-NDK as 32 bit libraries. I am copying native libraries inside my android applications libs/armeabi folder and then building my android application in AOSP(I have also modified device.mk to copy my libs in the /system/lib folder). Everything is working fine on Android Kitkat.

When i ported my application on Android-L(64bit platform) then i am not able to load my native libraries from Android application and error is like -

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

I am using following java code to load native library-

        if ( ENABLE_ANDROID_INTEGRATION )
        {
            System.load("/system/lib/libfoobar.so");
        }
        else
        {
            System.loadLibrary("foobar");
        }

When i am building my code with AOSP then ENABLE_ANDROID_INTEGRATION is true

More interestingly when i turned off ENABLE_ANDROID_INTEGRATION and build my application in Eclipse, outside AOSP as a normal "downloadable" application then my application is running fine on 64bit Android platform.

What i want to know - how can i build my application as a native android system application with 32 bit libraries(that means AOSP build) for 64 bit Android platform?

What i have tried - I used LOCAL_32_BIT_ONLY = true flag in my android application's Android.mk file, but it seams it is not useful. May be i am not fully aware of this flag use.

As i am running out of time so i preferred to post this question here in group instead of RnD. If anyone faced this problem then please guide.

Regards, Meraj

like image 910
Meraj Ahmad Avatar asked Dec 30 '14 21:12

Meraj Ahmad


People also ask

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

32-bit applications must link with 32-bit libraries, and 64-bit applications must link with 64-bit libraries. It is not possible to create or execute a 32-bit application using 64-bit libraries. The 32-bit libraries continue to be located in /usr/lib and /usr/ccs/lib .

Can you run 32-bit on 64-bit Android?

You can (almost) always run 32bit apps/programms on 64bit CPUs, but not the other way around. Lately, android devices are getting more and more RAM, the problem is with a 32bit app you can only access 4GB of RAM. In addition you can perform much more calculations on a 64bit CPU than on a 32bit CPU.

Is changing 64-bit armv8 a 32-bit mode to 64-bit mode possible?

Guest. Android OS can run on both 32-bit and 64-bit processor architectures. If you have a phone running the 32-bit version, you basically can upgrade to the 64-bit version.

How do I make my Android app support 64-bit?

Change build settings to output 64-bit libraries If you are using a version of Unity that supports 64-bit Android libraries, you can generate a 64-bit version of your app by adjusting your build settings. Use the IL2CPP backend as your Scripting Backend.


2 Answers

The reason why it works when installed as a third party application, is that on installation, the package manager scans the APK and checks if it uses native libraries, and if such are found, it stores which ABI they used (since it only installs libraries for one single ABI, so the info about which choice was made needs to be stored somewhere).

For an application that is installed system wide with the libraries in /system/lib, it's not clear that this particular application depends on some app specific libs in /system/lib (that aren't available in a 64 bit version in /system/lib64), so the package/application manager can't know that this particular app requires a specific ABI and thus runs it in 64 bit mode.

Setting LOCAL_32_BIT_ONLY probably only affects whether it should be compiled in 32 bit mode, not in which way it should be run.

An old (and probably outdated) report at http://www.slideshare.net/hidenorly/investigation-result-on-64-bit-support-in-aosp seems to suggest that the native libraries for apps should go into /system/lib/apkname, but this doesn't seem to be true on an actual Android 5.0 system. Instead, the libs seem to be in /system/app/appname/lib/abiname. Some apps seem to have native libs for multiple architectures (e.g. both "arm" and "arm64" as abiname), while others only have one single architecture (which would force the process to be started in that ABI mode).

So I think you need to alter the mechanism for how you install your native libraries (you said you manually modified device.mk) - I'm not familiar with how to build own apps as part of an AOSP build, but I'd recommend trying to look at the existing bundled apps how they do it, this commit may be related: https://android.googlesource.com/platform/packages/apps/Terminal/+/1a161f75%5E%21/

like image 86
mstorsjo Avatar answered Oct 19 '22 13:10

mstorsjo


I have the same problem and found the answer here and here Delete all 64-bit libraries and left only 32-bit libs: In Android.mk:

APP_API := armeabi armeabi-v7a x86 mips

In build.gradle(Module:app):

ndk {
    moduleName "<module_name>"
    abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
like image 43
Dmitry Velychko Avatar answered Oct 19 '22 14:10

Dmitry Velychko