我正在使用下面的代码来确定用户是否已将运行时更改为 ART(Xamarin 当前不支持并导致我的应用程序崩溃)。
private bool IsART {
get {
try {
var systemProperties = Java.Lang.Class.ForName("android.os.SystemProperties");
var strClass = Java.Lang.Class.FromType(typeof (Java.Lang.String));
Method get = systemProperties.GetMethod("get", strClass, strClass);
string value = get.Invoke(systemProperties, "persist.sys.dalvik.vm.lib", "Dalvik").ToString();
if ("libart.so".Equals(value) || "libartd.so".Equals(value)) {
return true;
}
}
catch {}
return false;
}
}
在我的测试设备(HTC One X)上运行良好,但在启用 ART 的 Nexus 5 上运行时,会导致 SIGSEGV 错误,并带有以下堆栈跟踪(try-catch 无法捕获):
03-18 19:39:30.045 E/mono-rt (26924): at <unknown> <0xffffffff>
03-18 19:39:30.045 E/mono-rt (26924): at (wrapper managed-to-native) object.wrapper_native_0x415b0f9d (intptr,intptr,intptr,Android.Runtime.JValue[]) <0xffffffff>
03-18 19:39:30.045 E/mono-rt (26924): at (wrapper delegate-invoke) <Module>.invoke_intptr__this___intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,Android.Runtime.JValue[]) <0xffffffff>
03-18 19:39:30.045 E/mono-rt (26924): at Android.Runtime.JNIEnv.CallStaticObjectMethod (intptr,intptr,Android.Runtime.JValue[]) <0x00097>
03-18 19:39:30.045 E/mono-rt (26924): at Java.Lang.Class.ForName (string) <0x000ef>
03-18 19:39:30.045 E/mono-rt (26924): at AwesomeApp.Droid.SplashScreen.get_IsART () <0x0001b>