Search code examples
c#androidxamarinxamarin.androidhockeyapp

Unusable component HockeyApp for Android (Xamarin component store)


I was trying to put the component mentioned above into operation.

http://components.xamarin.com/view/hockeyappios

I created a very simple project based on Xamarin Studio template (Android Ice Cream Sandwich Application) Then I added the necessary code for sending exceptions to HockeyApp. This code is described on following page

http://components.xamarin.com/gettingstarted/hockeyappandroid

Unfortunately, I found a major problem with storing exceptions info file

HockeyApp.ManagedExceptionHandler.SaveException (e.ExceptionObject)

This call results in the following error

[mono-rt] Stacktrace:
[mono-rt] 
[mono-rt]   at <unknown> <0xffffffff>
[mono-rt]   at (wrapper managed-to-native) object.wrapper_native_0x407339b5 (intptr,string) <IL 0x00038, 0xffffffff>
[mono-rt]   at Android.Runtime.JNIEnv.FindClass (string) [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:377
[mono-rt]   at Android.Runtime.JNIEnv.FindClass (string,intptr&) [0x00014] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:409
[mono-rt]   at Android.OS.Looper.get_class_ref () [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.OS.Looper.cs:14
[mono-rt]   at Android.OS.Looper.get_MainLooper () [0x00014] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.OS.Looper.cs:34
[mono-rt]   at Android.App.SyncContext.Send (System.Threading.SendOrPostCallback,object) [0x00014] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:24
[mono-rt]   at HockeyApp.ManagedExceptionHandler.Save (string) <IL 0x0001f, 0x00157>
[mono-rt]   at HockeyApp.ManagedExceptionHandler.SaveException (object) <IL 0x00006, 0x0006b>
[mono-rt]   at HockeyAppTest.App.<OnCreate>b__0 (object,System.UnhandledExceptionEventArgs) [0x00002] in c:\Snapshot\HockeyAppTest\Application.cs:33
[mono-rt]   at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object_object (object,intptr,intptr,intptr) <IL 0x0005a, 0xffffffff>
[mono-rt] 
[mono-rt] =================================================================
[mono-rt] Got a SIGSEGV while executing native code. This usually indicates
[mono-rt] a fatal error in the mono runtime or one of the native libraries 
[mono-rt] used by your application.
[mono-rt] =================================================================

During the examination of the problem, I came across following information

  • Handled exception can be stored without problems
  • Problem occurs only in AppDomain.CurrentDomain.UnhandledException handler

Then I tried the following code inside AppDomain.CurrentDomain.UnhandledException handler

string eStr = e.ExceptionObject.ToString();
Java.Lang.Throwable thr = new Java.Lang.Throwable(eStr);

This code led to very similar error

[mono-rt] Stacktrace:
[mono-rt] 
[mono-rt]   at <unknown> <0xffffffff>
[mono-rt]   at (wrapper managed-to-native) object.wrapper_native_0x4072e4e5 (intptr,intptr,int) <IL 0x00027, 0xffffffff>
[mono-rt]   at Android.Runtime.JNIEnv.NewString (string) [0x00017] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:666
[mono-rt]   at Java.Lang.Throwable..ctor (string) [0x00022] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/b5dc5ce9/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Java.Lang.Throwable.cs:50
[mono-rt]   at HockeyAppTest.App.<OnCreate>b__0 (object,System.UnhandledExceptionEventArgs) [0x0000d] in c:\Snapshot\HockeyAppTest\Application.cs:34
[mono-rt]   at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object_object (object,intptr,intptr,intptr) <IL 0x0005a, 0xffffffff>

Is this a general problem with code call witch use “java binding” inside AppDomain.CurrentDomain.UnhandledException ?


Solution

  • The second error is because the exception handler for unhandled c# exceptions runs in a funny space that doesn't really have JNI access.

    You can make it work without the component with a little wrapper glue by directly writing out the C# exceptions to the HockeyApp format and only report the Java exceptions directly to the HockeyApp library.

    This is what I use https://github.com/tpurtell/AndroidHockeyApp/blob/master/Additions/TraceWriter.cs#L84

    HockeyApp is a little pedantic about the formatting of the Exception, so this code is not quite perfect and will cause some stack traces to be grouped together by exception name on their website, but the exceptions will all make it t here.