Skip to content

[Net 9][Android] Runtime crash on Sentry.SentrySdk.Init #4030

@AmaruTrai

Description

@AmaruTrai

Package

Sentry

.NET Flavor

.NET

.NET Version

9.0.0

OS

Android

SDK Version

5.3.0

Self-Hosted Sentry Version

No response

Steps to Reproduce

After update sentry sdk from version "5.2.0" to "5.3.0" app start crash with runtime error.

  1. Setup Net 9 project for target net9.0-android
  2. Add package Sentry - 5.3.0
  3. Setup SentrySDK.Init
  4. Build and deploy release version

Exception log from logcat:

java.lang.IllegalArgumentException: DSN is required. Use empty string or set enabled to false in SentryOptions to disable SDK.
	at io.sentry.Sentry.initConfigurations(Sentry.java:396)
	at io.sentry.Sentry.init(Sentry.java:234)
	at io.sentry.Sentry.init(Sentry.java:167)
	at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:93)
	at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:76)
	at crc6485b6303acb051c43.Window_ChoreographerCallback.n_doFrame(Native Method)
	at crc6485b6303acb051c43.Window_ChoreographerCallback.doFrame(Window_ChoreographerCallback.java:29)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1688)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1699)
	at android.view.Choreographer.doCallbacks(Choreographer.java:1154)
	at android.view.Choreographer.doFrame(Choreographer.java:1070)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1647)
	at android.os.Handler.handleCallback(Handler.java:958)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:230)
	at android.os.Looper.loop(Looper.java:319)
	at android.app.ActivityThread.main(ActivityThread.java:9063)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:588)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

If setup DSN in Android.xml or setup enable/init options, crash log change to:

android.runtime.JavaProxyThrowable: [System.NullReferenceException]: Object reference not set to an instance of an object
	at Sentry.Android.AndroidEventProcessor..ctor + 0x11(Unknown Source)
	at Sentry.SentrySdk.InitSentryAndroidSdk + 0xbe(Unknown Source)
	at Sentry.SentrySdk.InitHub + 0x77(Unknown Source)
	at Sentry.SentrySdk.Init + 0x0(Unknown Source)
	at Sentry.SentrySdk.Init + 0x10(Unknown Source)
	at NDA code

Project setting for release version:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net9.0-android</TargetFramework>
        <RuntimeIdentifiers>android-arm;android-arm64;android-x86;android-x64</RuntimeIdentifiers>
        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
        <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
        <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
      <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
      <RunAOTCompilation>true</RunAOTCompilation>
      <EnableLLVM>false</EnableLLVM>
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="Sentry" Version="5.3.0" />
      <PackageReference Include="Xamarin.AndroidX.Compose.Foundation" Version="1.7.8" />
      <PackageReference Include="Xamarin.AndroidX.Compose.Material" Version="1.7.8" />
      <PackageReference Include="Xamarin.AndroidX.Compose.Runtime" Version="1.7.8" />
      <PackageReference Include="Xamarin.AndroidX.Compose.UI" Version="1.7.8" />
      <PackageReference Include="Xamarin.AndroidX.Lifecycle.Common" Version="2.8.7.2" />
      <PackageReference Include="Xamarin.AndroidX.Lifecycle.Process" Version="2.8.7.2" />
      <PackageReference Include="Xamarin.AndroidX.Lifecycle.Runtime" Version="2.8.7.2" />
      <PackageReference Include="Xamarin.AndroidX.Lifecycle.ViewModel" Version="2.8.7.2" />
    </ItemGroup>
</Project>

Sentry init:

	SentrySdk.Init(options => {
			options.Dsn = "*****";
			options.AutoSessionTracking = true;
			options.IsGlobalModeEnabled = true;
			options.SendDefaultPii = true;
			options.UseAsyncFileIO = true;

#if ANDROID
			options.Native.AnrEnabled = true;
			options.Native.AnrReportInDebug = true;
			options.Android.LogCatIntegration = LogCatIntegrationType.All;
			options.Android.LogCatMaxLines = 300;
#endif
		});

Expected Result

No runtime crash

Actual Result

Crash on runtime.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions