diff --git a/CHANGELOG.md b/CHANGELOG.md
index 97a13b89c..03ac7cede 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,10 @@
## Unreleased
+### Fixes
+
+- The SDK no longer closes the underlying native SDK during the games shutdown if native support has not been enabled. This allows the SDK to support and capture errors in case of building the game as a library on a mobile (Android or iOS) game. ([#1897](https://github.com/getsentry/sentry-unity/pull/1897))
+
### Dependencies
- Bump .NET SDK from v4.12.1 to v4.13.0 ([#1879](https://github.com/getsentry/sentry-unity/pull/1879), [#1885](https://github.com/getsentry/sentry-unity/pull/1885))
diff --git a/package-dev/Runtime/SentryInitialization.cs b/package-dev/Runtime/SentryInitialization.cs
index c786d8e96..d164e8ae0 100644
--- a/package-dev/Runtime/SentryInitialization.cs
+++ b/package-dev/Runtime/SentryInitialization.cs
@@ -112,9 +112,9 @@ public static void Init()
{
// Closing down the native layer that are set up during build and self-initialize
#if SENTRY_NATIVE_COCOA
- SentryNativeCocoa.Close(options.DiagnosticLogger);
+ SentryNativeCocoa.Close(options, sentryUnityInfo);
#elif SENTRY_NATIVE_ANDROID
- SentryNativeAndroid.Close(options.DiagnosticLogger);
+ SentryNativeAndroid.Close(options, sentryUnityInfo);
#endif
}
}
diff --git a/src/Sentry.Unity.Android/SentryNativeAndroid.cs b/src/Sentry.Unity.Android/SentryNativeAndroid.cs
index 2a4ba3086..a6db01640 100644
--- a/src/Sentry.Unity.Android/SentryNativeAndroid.cs
+++ b/src/Sentry.Unity.Android/SentryNativeAndroid.cs
@@ -1,5 +1,7 @@
using System;
using Sentry.Extensibility;
+using Sentry.Unity.Integrations;
+using UnityEngine;
using UnityEngine.Analytics;
namespace Sentry.Unity.Android;
@@ -74,7 +76,7 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry
e, "Failed to reinstall backend. Captured native crashes will miss scope data and tag.");
}
- options.NativeSupportCloseCallback = () => Close(options.DiagnosticLogger);
+ options.NativeSupportCloseCallback = () => Close(options, sentryUnityInfo);
options.DefaultUserId = SentryJava.GetInstallationId(JniExecutor);
if (string.IsNullOrEmpty(options.DefaultUserId))
@@ -101,15 +103,19 @@ public static void Configure(SentryUnityOptions options, ISentryUnityInfo sentry
///
/// Closes the native Android support.
///
- public static void Close(IDiagnosticLogger? logger = null)
+ public static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) =>
+ Close(options, sentryUnityInfo, ApplicationAdapter.Instance.Platform);
+
+ internal static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo, RuntimePlatform platform)
{
- if (!SentryJava.IsSentryJavaPresent())
+ if (!sentryUnityInfo.IsNativeSupportEnabled(options, platform) || !SentryJava.IsSentryJavaPresent())
{
+ options.DiagnosticLogger?.LogDebug("Native Support is not enable. Skipping closing the native SDK");
return;
}
// Sentry Native is initialized and closed by the Java SDK, no need to call into it directly
- logger?.LogDebug("Closing the sentry-java SDK");
+ options.DiagnosticLogger?.LogDebug("Closing the sentry-java SDK");
// This is an edge-case where the Android SDK has been enabled and setup during build-time but is being
// shut down at runtime. In this case Configure() has not been called and there is no JniExecutor yet
diff --git a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs
index c191822de..35c529195 100644
--- a/src/Sentry.Unity.iOS/SentryNativeCocoa.cs
+++ b/src/Sentry.Unity.iOS/SentryNativeCocoa.cs
@@ -53,7 +53,7 @@ internal static void Configure(SentryUnityOptions options, ISentryUnityInfo sent
return crashedLastRun;
};
- options.NativeSupportCloseCallback += () => Close(options.DiagnosticLogger);
+ options.NativeSupportCloseCallback += () => Close(options, sentryUnityInfo, platform);
if (sentryUnityInfo.IL2CPP)
{
options.DefaultUserId = SentryCocoaBridgeProxy.GetInstallationId();
@@ -81,9 +81,18 @@ internal static void Configure(SentryUnityOptions options, ISentryUnityInfo sent
///
/// Closes the native Cocoa support.
///
- public static void Close(IDiagnosticLogger? logger = null)
+ public static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo) =>
+ Close(options, sentryUnityInfo, ApplicationAdapter.Instance.Platform);
+
+ internal static void Close(SentryUnityOptions options, ISentryUnityInfo sentryUnityInfo, RuntimePlatform platform)
{
- logger?.LogDebug("Closing the sentry-cocoa SDK");
+ if (!sentryUnityInfo.IsNativeSupportEnabled(options, platform))
+ {
+ options.DiagnosticLogger?.LogDebug("Native Support is not enable. Skipping closing the native SDK");
+ return;
+ }
+
+ options.DiagnosticLogger?.LogDebug("Closing the sentry-cocoa SDK");
SentryCocoaBridgeProxy.Close();
}
}