Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding libraries like Crashlytics use Throwable, which which leads to unusable logs #9442

Open
DavidMarquezF opened this issue Oct 22, 2024 · 1 comment
Assignees
Labels
Area: Mono.Android Issues with the Android API binding (Mono.Android.dll).

Comments

@DavidMarquezF
Copy link

DavidMarquezF commented Oct 22, 2024

Android framework version

net8.0-android

Affected platform version

Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.11.5

Description

I initially opened this issue in the AndroidX bindings but was told that here would be a better place for this issue. (see dotnet/android-libraries#1011)

The main issue is that Crashlytics uses Java.Lang.Throwable. To convert our exceptions to this type we can use Java.Lang.Throwable.FromException. However, the resulting crash logs are pretty hard to read and use compared to when we were using AppCenter (to be deprecated in 2025). On top of that inner exceptions are not even displayed, so for some issues it's impossible to know what actually happened.

Given the deprecation of AppCenter and Firebase being the logical alternative (other than sentry), it feels like a big downgrade to not be able to get proper readable logs.

I believe this could improve a lot and make Crashlytics more useful if it was solved at the .net android level

Steps to Reproduce

  1. Create a new project and set up Firebase Crashlytics
  2. Throw a simple error -> This shows that the crashlytics error is usable but hard to understand, also firebase crashlytics groupping will not work very well in this case
  3. Create an inner exception like starting a task and throwing and error from inside (the inner exception is not logged and thus you loose crucial information)

Did you find any workaround?

You have some control over managed crashes by preparing the throwable a bit better, but unmanaged crashes are directly handled by Firebase, which doesn't leave us any way to improve it

Relevant log output

Example of AppCenter crash:

Xamarin Exception Stack:
System.Exception: Exception NavigateToFirstViewModel
  at x.AppStart.NavigateToFirstViewModel(Object hint)
  at MvvmCross.ViewModels.MvxAppStart.StartAsync(Object hint)
  at x.Droid.Activities.RootActivity.RunAppStartAsync(Bundle bundle)
  at x.Droid.Activities.RootActivity.OnResume()
  at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
  at Android.App.SyncContext.<>c__DisplayClass2_0.<Post>b__0()
  at Java.Lang.Thread.RunnableImplementor.Run()
  at Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz)
--- End of inner exception stack trace ---
  System.NullReferenceException: Object reference not set to an instance of an object
    at x.Droid.UIManager.KeyboardHelper.EnableKeyboard(Activity activity)
    at x.Droid.MvxServices.UserInterfaceService.SetDisableKeyboard(Boolean disabled)
    at x.AppStart.NavigateToFirstViewModel(IAppStartStatusService appStartStatus, IMvxNavigationService navigationService, BusinessLogic dataService, IApplyUserSettingsService settingsService, IUserInterfaceService userSettingsService, IEventTracker eventTracker, String startName)
    at x.AppStart.NavigateToFirstViewModel(Object hint)

Same issue in Crashlytics:

Fatal Exception: android.runtime.JavaProxyThrowable: [System.Exception]: Exception NavigateToFirstViewModel
       at x.AppStart+<NavigateToFirstViewModel>d__6.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification()
       at MvvmCross.ViewModels.MvxAppStart+<StartAsync>d__5.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification()
       at x.Droid.Activities.RootActivity+<RunAppStartAsync>d__10.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification()
       at x.Droid.Activities.RootActivity+<OnResume>d__8.MoveNext()
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Threading.Tasks.Task+<>c.<ThrowAsync>b__128_0()
       at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0()
       at Java.Lang.Thread+RunnableImplementor.Run()
       at Java.Lang.IRunnableInvoker.n_Run()
       at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V()
       at mono.java.lang.RunnableImplementor.n_run(SourceFile)
       at mono.java.lang.RunnableImplementor.run(SourceFile:1)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7680)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:423)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Looking at the whole crashlytics log, there is no reference at EnableKeyboard function, which is the one that threw the error

@DavidMarquezF DavidMarquezF added the needs-triage Issues that need to be assigned. label Oct 22, 2024
@jpobst
Copy link
Contributor

jpobst commented Oct 22, 2024

This uses Java.Lang.Throwable.FromException where we perform stack trace translation. Perhaps there is a bug or enhancement here that could be done to provide a better trace?

@jpobst jpobst assigned jonpryor and grendello and unassigned jpobst Oct 22, 2024
@jpobst jpobst added Area: Mono.Android Issues with the Android API binding (Mono.Android.dll). and removed needs-triage Issues that need to be assigned. labels Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Mono.Android Issues with the Android API binding (Mono.Android.dll).
Projects
None yet
Development

No branches or pull requests

4 participants