private static boolean is64BitImpl() {
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// Android API 21之前不支持64位CPU
return false;
}
Class<?> clzVMRuntime = Class.forName("dalvik.system.VMRuntime");
if (clzVMRuntime == null) {
return false;
}
Method mthVMRuntimeGet = clzVMRuntime.getDeclaredMethod("getRuntime");
if (mthVMRuntimeGet == null) {
return false;
}
Object objVMRuntime = mthVMRuntimeGet.invoke(null);
if (objVMRuntime == null) {
return false;
}
Method sVMRuntimeIs64BitMethod = clzVMRuntime.getDeclaredMethod("is64Bit");
if (sVMRuntimeIs64BitMethod == null) {
return false;
}
Object objIs64Bit = sVMRuntimeIs64BitMethod.invoke(objVMRuntime);
if (objIs64Bit instanceof Boolean) {
return (boolean) objIs64Bit;
}
} catch (Throwable e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
return false;
try {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// Android API 21之前不支持64位CPU
return false;
}
Class<?> clzVMRuntime = Class.forName("dalvik.system.VMRuntime");
if (clzVMRuntime == null) {
return false;
}
Method mthVMRuntimeGet = clzVMRuntime.getDeclaredMethod("getRuntime");
if (mthVMRuntimeGet == null) {
return false;
}
Object objVMRuntime = mthVMRuntimeGet.invoke(null);
if (objVMRuntime == null) {
return false;
}
Method sVMRuntimeIs64BitMethod = clzVMRuntime.getDeclaredMethod("is64Bit");
if (sVMRuntimeIs64BitMethod == null) {
return false;
}
Object objIs64Bit = sVMRuntimeIs64BitMethod.invoke(objVMRuntime);
if (objIs64Bit instanceof Boolean) {
return (boolean) objIs64Bit;
}
} catch (Throwable e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
return false;
}
转自:replugin-host-lib开源代码