2014-03-19 24 views
0

我使用下面的代碼來確定用戶是否已將運行時更改爲ART(Xamarin目前不支持並導致我的應用程序崩潰)。MonoDroid - SIGSEGV檢查Dalvik vs ART時

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的),但是當上啓用的Nexus 5 ART運行,導致與以下堆棧跟蹤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> 
+0

你可以嘗試這個實現檢測ART運行時? - http://stackoverflow.com/questions/22017813/how-can-i-detect-the-android-runtime-dalvik-or-art-in-xamarin – choper

+0

代碼已經非常相似了!在兩個實現中都存在的'Java.Lang.Class.ForName'中發生異常。 – Jamie

+0

當你調用這個方法?我的意思是在活動OnCreate或另一個? – choper

回答

0

截至Xamarin.Android 4.12.3,藝術是正式支持這樣的錯誤不再出現。