Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force Android application to use either 32bit or 64 bit libraries

On a Android device with 64bit ARM, would have two variants of many libraries, 32bit and 64 bit, and their performance could be different. I want to know if there is a way to force the application to use either 32bit or 64bit libraries.

like image 266
kanna Avatar asked Aug 06 '15 17:08

kanna


People also ask

Can a 64-bit Android run 32-bit programs?

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.

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 .

How do I know if APK is 32 or 64-bit?

Nowadays if the developer publishes the app as app-bundle Google only sends those partial APK to your device that match your device platform. Hence if you see an APK file named "armv8" it is 64bit, in case of an armv7[e] it is 32bit.


3 Answers

  1. If your apk is written in pure java (without jni), on 64-bit-primiary/32-bit-secondary Android OS, your app will always run in 64 bit mode by default, but if you want your app to run in 32 bit mode, you can create a dummy *.so file and put it under <your apk name>/libs/armeabi/ to force AndroidRuntime to create a 32 bit VM for your app

  2. If some function of your apk is written in jni (there's any *.so file in <your apk name>/libs/ folder), you can use following command to make it run in 64 or 32 bit VM:

    • To run in 32 bit mode, because only 32 bit native libs will be installed

    adb shell install --abi armeabi-v7a <path to your apk>

    • To run in 64 bit mode, because only 64 bit native libs will be installed

    adb shell install --abi arm64-v8a <path to your apk>

like image 50
tonykwok Avatar answered Jan 03 '23 20:01

tonykwok


ABI can be specified when the apk is installed.

adb install --abi <path to apk>

In case ARM device,

To run in 32 bit mode install using,

adb install --abi armeabi-v7a <path to apk>

To run in 64 bit mode install using,

adb install --abi arm64-v8a <path to apk>

like image 37
kanna Avatar answered Jan 03 '23 20:01

kanna


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

Try this in you Android.mk

LOCAL_MULTILIB := 32 // or 64
like image 45
arodriguezdonaire Avatar answered Jan 03 '23 18:01

arodriguezdonaire