如何检测 android 设备是 64 位还是 32 位处理器?

How to detect android device is 64 bit or 32 bit processor?

我正在尝试为这个问题找到最佳解决方案。原因是我们应用程序中的库不能 运行 与 64 位处理器一起使用,所以在这种情况下我需要将其关闭。 我发现在 Android 版本 21 (lolipop) 及更高版本中,我们可以通过使用 Build.SUPPORTED_64_BIT_ABIS 轻松检测到设备是 32 位或 64 位处理器,如果它 returns 字符串数组然后有 0 个元素......哈!该设备是 32 位处理器。 较低的 android 版本怎么样? Build.SUPPORTED_64_BIT_ABIS 仅支持 android Lolipop 版本及更高版本。 谢谢和最好的问候, 祝你们一切顺利!

简单回答:无需在 Lollipop 以下的 Android 版本上进行检查。这是因为 Lollipop 引入了对 64 位架构的平台支持,Android-Lollipop 以下的版本不会 运行 使用 64 位处理器。

Android 5.0 introduces platform support for 64-bit architectures—used by the Nexus 9's NVIDIA Tegra K1. Optimizations provide larger address space and improved performance for certain compute workloads. Apps written in the Java language run as 64-bit apps automatically—no modifications are needed. If your app uses native code, we’ve extended the NDK to support new ABIs for ARM v8, and x86-64, and MIPS-64. (Source)

 try {
            boolean  isArm64 = false;

            BufferedReader localBufferedReader = new BufferedReader(new FileReader("/proc/cpuinfo"));
            if (localBufferedReader.readLine().contains("aarch64")) {
                isArm64 = true;
            }
            localBufferedReader.close();
        } catch (IOException e) {
        }

或者

final boolean is64bit = Build.SUPPORTED_64_BIT_ABIS.length > 0;

首先将设备连接到系统, 在 windows 上,在命令提示符中键入此命令

adb shell cat  /proc/cpuinfo | findstr arc

在 linux 或 mac 基本系统打开终端并键入此命令

  adb shell cat  /proc/cpuinfo | grep arc

如果输出contain 32的第一行表示系统类型是32bit

第一行如果contain 64表示系统类型是64bit

32Bit 如果5.0以下,因为android支持64Bit 直到5.0.
5.0以上判断Build.SUPPORTED_ABIS是否支持64。

String bits;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    bits = TextUtils.join(", ", Build.SUPPORTED_ABIS).contains("64") ? "64-Bit" : "32-Bit";
} else {
    bits = "32-Bit";
}

您可以使用 Dev Tools 查看设备是 64 位还是 32 位。

我找到了API,按app进程区分

Process.is64Bit()

当然可以是arm 64或者x86-64

但是如果你只打包arm共享库,x86设备是安装不了你的app的。

所以这个方法是可行的。

如果您打包 x86 共享库,则以上答案 SUPPORTED_ABIS 有效。

如果您使用的是 ADB

adb shell cat /proc/cpuinfo | grep rch

最多输出:

架构7 -> 32位

架构 8 -> 64 位

  • this is an extension answer from @Naval Kishor Jha

  • tested in 6 models here

  • no root needed

如果您正在使用 JAVA

if(Build.SUPPORTED_64_BIT_ABIS.length>0)
  {
  //it's a 64bit
  }
  else
  {
  //it's a 32bit
  }