I'm using the below code to determine whether the user has changed the runtime to ART (which Xamarin currently doesn't support and causes my app to crash).

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;
        }
    }

Which works fine on my test device (HTC One X) but when run on a Nexus 5 with ART enabled, causes a SIGSEGV error with the following stack trace (which the try-catch doesn't 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>
有帮助吗?

解决方案

As of Xamarin.Android 4.12.3, ART is officially supported so the error no longer occurs.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top