0

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>
Charles
  • 50,943
  • 13
  • 104
  • 142
Jamie
  • 4,670
  • 5
  • 35
  • 49
  • Can you try this implementation for detecting ART runtime? - http://stackoverflow.com/questions/22017813/how-can-i-detect-the-android-runtime-dalvik-or-art-in-xamarin – choper Mar 19 '14 at 13:19
  • The code is pretty similar already! The exception occurs in `Java.Lang.Class.ForName` which is present in both implementations. – Jamie Mar 19 '14 at 15:15
  • When you call this method? I mean in activity OnCreate or in another one? – choper Mar 19 '14 at 15:36

1 Answers1

0

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

Jamie
  • 4,670
  • 5
  • 35
  • 49