众所周知,从Android 5.0开始,64位支持已经存在。我有一个非常简单的问题。我们是否可以通过编程方式检查当前运行的应用程序以何种模式运行,即32位还是64位?例如:我在我的Nexus 9上运行Facebook应用程序,那么我是否可以使用我的安卓应用程序来检查Facebook应用程序的进程是否以32位模式或64位模式运行?
众所周知,从Android 5.0开始,64位支持已经存在。我有一个非常简单的问题。我们是否可以通过编程方式检查当前运行的应用程序以何种模式运行,即32位还是64位?例如:我在我的Nexus 9上运行Facebook应用程序,那么我是否可以使用我的安卓应用程序来检查Facebook应用程序的进程是否以32位模式或64位模式运行?
在 Nexus 5x 中
String arch = System.getProperty("os.arch");
返回
armv8l
我的代码崩溃了,因为它不是 aarch64
。然而,
root@bullhead:/ # uname -m
aarch64
root@bullhead:/ # getprop ro.product.cpu.abilist
arm64-v8a,armeabi-v7a,armeabi
有线(Wired)。所以我改变了我的代码为
boolean is64 = (android.os.Build.VERSION.SDK_INT >= 21) && System.getProperty("ro.product.cpu.abilist").contains("64");
更新于2016-02-11
在三星三星Galaxy S5 Neo上,运行Android 5.1.1。
String arch = System.getProperty("os.arch");
返回aarch64
,但这不是64位设备!!!
ro.product.cpu.abilist
返回 armeabi-v7a, armeabi
bool is64Bit = System.getProperty("ro.product.cpu.abilist").contains("64");
检查是唯一的检查方式。
System.getProperty("os.arch")
。
虽然我没有在64位安卓上尝试过,但是如果设备是64位的话,它必须返回类似于'aarch64'的内容。
参考链接:http://developer.android.com/reference/java/lang/System.html#getProperty(java.lang.String)
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;
}
我认为,您可以使用 reflect 来获取 is64Bit 的结果。Android 6.0 开始提供了此 API 来检查您的进程。
android.os.Process.is64Bit()
public static boolean is64Bit() {
return (Build.SUPPORTED_64_BIT_ABIS!= null && Build.SUPPORTED_64_BIT_ABIS.length >0);
}
boolean is64Arch = Build.CPU_ABI.equalsIgnoreCase("x86_64") || Build.CPU_ABI.equalsIgnoreCase("arm64-v8a");
armv8l-unknown-linux-gnueabihf
。它出现在我拥有的基于Debian的ARM 32位Cortex-A7板上。工具链据说针对64位Aarch64 Cortex-A53 CPU。Autotools将编译器三元组armv8l-unknown-linux-gnueabihf
重写为armv7l-unknown-linux-gnueabihf
。 - jww