Skip to content

JNI DETECTED ERROR IN APPLICATION when reporting a crash in .NET MAUI Android App #3627

@dinisvieira-xo

Description

@dinisvieira-xo

Package

Sentry.Maui

.NET Flavor

.NET

.NET Version

8.0.8

OS

Android

SDK Version

4.11.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

This might be an hard to reproduce issue outside of our app. Basically I started having "random" crashes after 5 to 15 minutes of launching the app.
During this time the app is reporting crashes normally but suddenly crashes with something like "JNI DETECTED ERROR IN APPLICATION: JNI ERROR (app bug): jobject is an invalid global reference: 0x979a" followed by a native crash that didn't offer a lot of information.

I enabled GREF Logging and reproduced the issue to find more information on where the issue is occurring. After reproducing a few times the issue always seemed to point at Sentry.Maui.Internal.MauiDeviceData.ApplyMauiDeviceData as a related cause of this.

Important: If I comment the code that calls the SentrySdk.CaptureException the app runs with no crashes for hours.

Additional Info:

  • MAUI Version: 8.0.90
  • Also happened on Sentry SDK 4.10.2
  • Occurs in both Debug and Release
  • Occurs both with AttachScreenshot true or false
  • With GREF enabled (app running slower) the issue is even easier to reproduce (2 to 5 minutes)
  • For the specific app I'm running the app is reporting crashes at about 2 per minute (for testing purposes)
  • I'm using Prism.Pluggin.Logging to call Sentry, but I've already tried without Prism (simply calling Sentry directly to report) and the crash still occurs.

Sentry Options:

Debug = false;
AutoSessionTracking = true;
IsGlobalModeEnabled = false;
StackTraceMode = StackTraceMode.Enhanced;
DiagnosticLevel = SentryLevel.Debug;
TracesSampleRate = 1.0;
SampleRate = 1.0F;
MaxBreadcrumbs = 200;
CreateElementEventsBreadcrumbs = false;
IncludeBackgroundingStateInBreadcrumbs = false;
IncludeTextInBreadcrumbs = false;
IncludeTitleInBreadcrumbs = false;
SendDefaultPii = false;
AttachScreenshot = false;

Expected Result

App should not crash and continue reporting/logging to Sentry normally.

Actual Result

After 5 to 15 minutes of using the app it crashes at "random" moments when trying to report an issue to Sentry.

Stack Trace that I managed to get using GREF:

handle 0x15f36; key_handle 0x950a496: Java Type: `android/view/WindowManagerImpl`; MCW type: `Java.Lang.Object`
+g+ grefc 11514 gwrefc 0 obj-handle 0x6ff6179805/I -> new-handle 0x1460e/G from thread '.NET TP Worker'(3)
   at Android.Runtime.AndroidObjectReferenceManager.CreateGlobalReference(JniObjectReference value)
   at Java.Interop.JniObjectReference.NewGlobalRef()
   at Android.Runtime.JNIEnv.NewGlobalRef(IntPtr jobject)
   at Android.Runtime.AndroidValueManager.AddPeer(IJavaPeerable value, IntPtr handle, JniHandleOwnership transfer, IntPtr& handleField)
   at Java.Lang.Object.SetHandle(IntPtr value, JniHandleOwnership transfer)
   at Java.Lang.Object..ctor(IntPtr handle, JniHandleOwnership transfer)
   at Android.Net.NetworkInfo..ctor(IntPtr javaReference, JniHandleOwnership transfer)
   at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo , Object , IntPtr* , Exception& )
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Constructor(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
   at Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer)
   at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
   at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type)
   at Java.Lang.Object._GetObject[NetworkInfo](IntPtr handle, JniHandleOwnership transfer)
   at Java.Lang.Object.GetObject[NetworkInfo](IntPtr handle, JniHandleOwnership transfer)
   at Android.Net.ConnectivityManager.GetNetworkInfo(Network network)
   at Microsoft.Maui.Networking.ConnectivityImplementation.get_NetworkAccess()
   at Microsoft.Maui.Networking.Connectivity.get_NetworkAccess()
   at Sentry.Maui.Internal.MauiDeviceData.ApplyMauiDeviceData(Device device, IDiagnosticLogger logger)
   at Sentry.Maui.Internal.SentryMauiEventProcessor.Process(SentryEvent event)
   at Sentry.Extensibility.ISentryEventProcessorExtensions.DoProcessEvent(ISentryEventProcessor processor, SentryEvent event, SentryHint hint)
   at Sentry.SentryClient.DoSendEvent(SentryEvent event, SentryHint hint, Scope scope)
   at Sentry.SentryClient.CaptureEvent(SentryEvent event, Scope scope, SentryHint hint)
   at Sentry.Internal.Hub.CaptureEvent(SentryEvent evt, Scope scope, SentryHint hint)
   at Sentry.Internal.Hub.CaptureEvent(SentryEvent evt, SentryHint hint, Action`1 configureScope)
   at Sentry.Internal.Hub.CaptureEvent(SentryEvent evt, Action`1 configureScope)
   at Sentry.HubExtensions.CaptureException(IHub hub, Exception ex, Action`1 configureScope)
   at Sentry.SentrySdk.CaptureException(Exception exception, Action`1 configureScope)
   at Prism.Plugin.Logging.Sentry.SentryLoggingService.Report(Exception ex, IDictionary`2 properties, String filePath, String memberName, Int32 lineNumber)
   at Prism.Plugin.Logging.AggregateLogger.<>c__DisplayClass12_0.<Report>b__0(ILogger l)
   at Prism.Plugin.Logging.AggregateLogger.InvokeOnLogger(Action`1 logAction)
   at Prism.Plugin.Logging.AggregateLogger.Report(Exception ex, IDictionary`2 properties, String filePath, String memberName, Int32 lineNumber)
(... Stack Trace continues with App code that originated the report that we want to log ...)

Metadata

Metadata

No fields configured for issues without a type.

Projects

Status
Done
Status
No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions