我试图将上面提到的组件投入使用。
http://components.xamarin.com/view/hockeyappios
我创建了一个基于Xamarin Studio模板的非常简单的项目(Android Ice Cream Sandwich Application) 然后我添加了向HockeyApp发送异常的必要代码。此代码在下一页
中介绍http://components.xamarin.com/gettingstarted/hockeyappandroid
不幸的是,我发现了存储例外信息文件的主要问题
HockeyApp.ManagedExceptionHandler.SaveException (e.ExceptionObject)
此调用会导致以下错误
[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] =================================================================
在检查问题时,我发现了以下信息
然后我在AppDomain.CurrentDomain.UnhandledException处理程序
中尝试了以下代码string eStr = e.ExceptionObject.ToString();
Java.Lang.Throwable thr = new Java.Lang.Throwable(eStr);
此代码导致非常相似的错误
[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>
这是代码调用的一般问题,在AppDomain.CurrentDomain.UnhandledException中使用“java binding”吗?
答案 0 :(得分:4)
第二个错误是因为未处理的c#异常的异常处理程序在一个真正没有JNI访问权限的有趣空间中运行。
通过直接写出HockeyApp格式的C#异常并且只将Java异常直接报告给HockeyApp库,你可以使它在没有带有一点包装胶的组件的情况下工作。
这就是我使用的https://github.com/tpurtell/AndroidHockeyApp/blob/master/Additions/TraceWriter.cs#L84
HockeyApp对于Exception的格式化有点迂腐,所以这段代码不是很完美,会导致一些堆栈跟踪在他们的网站上通过异常名称组合在一起,但例外情况都会在这里进行。< / p>
答案 1 :(得分:0)
使用:强>
AndroidEnvironment.UnhandledExceptionRaiser += (s, e) =>
HockeyApp.ManagedExceptionHandler.SaveException(e.Exception);
Thread.DefaultUncaughtExceptionHandler = new UnCaughtExceptionHandler(this);
intead of:
AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
HockeyApp.ManagedExceptionHandler.SaveException (e.ExceptionObject);
其中UnCaughtExceptionHandler
只是您对该类的实现,而后者又使用HockeyApp.ManagedExceptionHandler.SaveException()
来记录异常(完整实现位于之下)。这是HockeyApp.ManagedExceptionHandler.SaveException(object exceptionObject)
引发的异常的一种解决方法,我想这最终会被整理出来。
class UnCaughtExceptionHandler : Java.Lang.Object, Thread.IUncaughtExceptionHandler
{
readonly Context context;
public UnCaughtExceptionHandler(Context context)
{
this.context = context;
}
public void UncaughtException(Thread thread, Throwable ex)
{
HockeyApp.ManagedExceptionHandler.SaveException(ex);
}
}