8

As we all know from Android 5.0.64bit support is there. I have very simple question. Can we check programmatically in what mode any application is running i.e. 32bit or 64bit? For example: I have Facebook app running on my Nexus 9, so can I check using my android app if Facebook app's process is running in 32bit mode or 64bit mode?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
  • I'm not sure where Clang got the triplet `armv8l-unknown-linux-gnueabihf`. It is showing up on a Debian-based ARM 32-bit Cortex-A7 board I have. The toolchain supposedly targets 64-bit Aarch64 Cortex-A53 cpus. Autotools rewrites the compiler triplet `armv8l-unknown-linux-gnueabihf` to `armv7l-unknown-linux-gnueabihf`. – jww May 01 '19 at 15:15

6 Answers6

10

In Nexus 5x

String arch = System.getProperty("os.arch");

returns

armv8l

it is not aarch64 and my code broke. However,

root@bullhead:/ # uname -m
aarch64

root@bullhead:/ # getprop ro.product.cpu.abilist
arm64-v8a,armeabi-v7a,armeabi

Wired. So I changed my code to

boolean is64 = (android.os.Build.VERSION.SDK_INT >= 21) && System.getProperty("ro.product.cpu.abilist").contains("64");

Updated on 2016-02-11

In Samsung Samsung Galaxy S5 Neo, Android 5.1.1

String arch = System.getProperty("os.arch");

returns aarch64 but it is not 64-bit device!!!

ro.product.cpu.abilist returns armeabi-v7a,armeabi

bool is64Bit =   System.getProperty("ro.product.cpu.abilist").contains("64");

check is the only way to check.

kakopappa
  • 5,023
  • 5
  • 54
  • 73
5

Try System.getProperty("os.arch"). I haven't tried it on 64-bit android, but it must return something like 'aarch64' in case of 64 bit device.

http://developer.android.com/reference/java/lang/System.html#getProperty(java.lang.String)

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
Torbik
  • 489
  • 3
  • 10
4
    public static boolean is64Bit() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //Added in API level 23
            return Process.is64Bit();
        }
        try {
            Class cls = Class.forName("dalvik.system.VMRuntime");
            Method getRuntimeMethod = cls.getDeclaredMethod("getRuntime");
            Object vmRuntime = getRuntimeMethod.invoke(null);
            Method is64BitMethod = cls.getDeclaredMethod("is64Bit");
            Object is64Bit = is64BitMethod.invoke(vmRuntime);
            if (is64Bit instanceof Boolean) {
                return (boolean) is64Bit;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

IMO, you can use reflect to get the result of is64Bit. Android 6.0 began to provide this api to check your process.

android.os.Process.is64Bit() 
ouhuijun
  • 41
  • 4
1

In my experience (if your minSdkVersion is >= 21) the best way is to check the size of the array Build.SUPPORTED_64_BIT_ABIS. (see https://developer.android.com/reference/android/os/Build#SUPPORTED_64_BIT_ABIS)

Something like this:

public static boolean is64Bit() {
 return (Build.SUPPORTED_64_BIT_ABIS!= null && Build.SUPPORTED_64_BIT_ABIS.length >0);
}
Alecs
  • 2,900
  • 1
  • 22
  • 25
0

What makes you think your device isn't 64-bit? The specs for the phone indicate it uses an Exynos 7 Octa 7580 which is arm8 and 64-bit.

EntangledLoops
  • 1,951
  • 1
  • 23
  • 36
0
boolean is64Arch = Build.CPU_ABI.equalsIgnoreCase("x86_64") || Build.CPU_ABI.equalsIgnoreCase("arm64-v8a");
  • 3
    Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes. – Mark Rotteveel Aug 16 '20 at 07:55