From 1322448c2d7b08bb5e5e5372d5ffa4cf4d630aec Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 16 Feb 2026 11:35:33 +0100 Subject: [PATCH 01/10] strictmode workaround --- test/IntegrationTest/Integration.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/IntegrationTest/Integration.Tests.ps1 b/test/IntegrationTest/Integration.Tests.ps1 index a07a897bc..39f401954 100644 --- a/test/IntegrationTest/Integration.Tests.ps1 +++ b/test/IntegrationTest/Integration.Tests.ps1 @@ -9,6 +9,9 @@ Set-StrictMode -Version latest $ErrorActionPreference = "Stop" +$global:DebugPreference = "Continue" + +. $PSScriptRoot/../Scripts.Integration.Test/common.ps1 # Import app-runner modules . $PSScriptRoot/../../modules/app-runner/import-modules.ps1 From caadc648888201632243e6f1cbaa4a0d61b00796 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 16 Feb 2026 14:27:58 +0100 Subject: [PATCH 02/10] . --- test/IntegrationTest/Integration.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/IntegrationTest/Integration.Tests.ps1 b/test/IntegrationTest/Integration.Tests.ps1 index 39f401954..6a7a9cc0e 100644 --- a/test/IntegrationTest/Integration.Tests.ps1 +++ b/test/IntegrationTest/Integration.Tests.ps1 @@ -11,8 +11,6 @@ Set-StrictMode -Version latest $ErrorActionPreference = "Stop" $global:DebugPreference = "Continue" -. $PSScriptRoot/../Scripts.Integration.Test/common.ps1 - # Import app-runner modules . $PSScriptRoot/../../modules/app-runner/import-modules.ps1 From 5a532ecbb318e444fa64c8cfb67b1133e5909306 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 16 Feb 2026 15:37:06 +0100 Subject: [PATCH 03/10] Debug log level --- test/IntegrationTest/Integration.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/test/IntegrationTest/Integration.Tests.ps1 b/test/IntegrationTest/Integration.Tests.ps1 index 6a7a9cc0e..a07a897bc 100644 --- a/test/IntegrationTest/Integration.Tests.ps1 +++ b/test/IntegrationTest/Integration.Tests.ps1 @@ -9,7 +9,6 @@ Set-StrictMode -Version latest $ErrorActionPreference = "Stop" -$global:DebugPreference = "Continue" # Import app-runner modules . $PSScriptRoot/../../modules/app-runner/import-modules.ps1 From d6b97785867c3736c5d03271900b53f700d59441 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Mon, 16 Feb 2026 16:33:36 +0100 Subject: [PATCH 04/10] fallback to activity --- test/IntegrationTest/Integration.Tests.ps1 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/IntegrationTest/Integration.Tests.ps1 b/test/IntegrationTest/Integration.Tests.ps1 index a07a897bc..8fb361e3e 100644 --- a/test/IntegrationTest/Integration.Tests.ps1 +++ b/test/IntegrationTest/Integration.Tests.ps1 @@ -30,7 +30,20 @@ BeforeAll { Write-Host "Running $Action..." $extras = @("-e", "test", $Action) - $runResult = Invoke-DeviceApp -ExecutablePath $script:AndroidComponent -Arguments $extras + + try { + $runResult = Invoke-DeviceApp -ExecutablePath $script:AndroidComponent -Arguments $extras + } + catch { + if ($_.Exception.Message -match "Activity class .* does not exist" -or $_.Exception.Message -match "Error type 3") { + Write-Host "Activity not found, trying fallback: $($script:FallbackAndroidComponent)" + $script:AndroidComponent = $script:FallbackAndroidComponent + $runResult = Invoke-DeviceApp -ExecutablePath $script:AndroidComponent -Arguments $extras + } + else { + throw + } + } # Save result to JSON file $runResult | ConvertTo-Json -Depth 5 | Out-File -FilePath (Get-OutputFilePath "${Action}-result.json") From 6530239e49c2f66f4bdb258a23a1b7d79ea915c6 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Tue, 17 Feb 2026 10:15:34 +0100 Subject: [PATCH 05/10] Drop stripping level for older than 6 --- test/Scripts.Integration.Test/Editor/Builder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Scripts.Integration.Test/Editor/Builder.cs b/test/Scripts.Integration.Test/Editor/Builder.cs index c3f395e67..bb2ae779c 100644 --- a/test/Scripts.Integration.Test/Editor/Builder.cs +++ b/test/Scripts.Integration.Test/Editor/Builder.cs @@ -37,7 +37,7 @@ public static void BuildIl2CPPPlayer(BuildTarget target, BuildTargetGroup group, #endif Debug.Log("Builder: Configuring code stripping level"); -#if UNITY_2022_1_OR_NEWER +#if UNITY_6000_0_OR_NEWER PlayerSettings.SetManagedStrippingLevel(NamedBuildTarget.FromBuildTargetGroup(group), ManagedStrippingLevel.High); #else PlayerSettings.SetManagedStrippingLevel(NamedBuildTarget.FromBuildTargetGroup(group), ManagedStrippingLevel.Low); From 76621ef7b32991c6a685c326a3e4d7f1f14b392a Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 19 Feb 2026 14:24:40 +0100 Subject: [PATCH 06/10] Mark crash-capture skipped tests as Skipped instead of silently passing --- test/IntegrationTest/CommonTestCases.ps1 | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/IntegrationTest/CommonTestCases.ps1 b/test/IntegrationTest/CommonTestCases.ps1 index b38fb675e..581a32d60 100644 --- a/test/IntegrationTest/CommonTestCases.ps1 +++ b/test/IntegrationTest/CommonTestCases.ps1 @@ -53,6 +53,11 @@ $CommonTestCases = @( @{ Name = "Contains user information"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) + if ($TestType -eq "crash-capture") { + Set-ItResult -Skipped -Because "user context may not survive native crashes" + return + } + $SentryEvent.user | Should -Not -BeNullOrEmpty $SentryEvent.user.username | Should -Be "TestUser" $SentryEvent.user.email | Should -Be "user-mail@test.abc" @@ -62,6 +67,11 @@ $CommonTestCases = @( @{ Name = "Contains breadcrumbs"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) + if ($TestType -eq "crash-capture") { + Set-ItResult -Skipped -Because "breadcrumbs may not survive native crashes" + return + } + $SentryEvent.breadcrumbs | Should -Not -BeNullOrEmpty $SentryEvent.breadcrumbs.values | Should -Not -BeNullOrEmpty } @@ -69,6 +79,11 @@ $CommonTestCases = @( @{ Name = "Contains expected breadcrumbs"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) + if ($TestType -eq "crash-capture") { + Set-ItResult -Skipped -Because "breadcrumbs may not survive native crashes" + return + } + $SentryEvent.breadcrumbs.values | Should -Not -BeNullOrEmpty $SentryEvent.breadcrumbs.values | Where-Object { $_.message -eq "Integration test started" } | Should -Not -BeNullOrEmpty $SentryEvent.breadcrumbs.values | Where-Object { $_.message -eq "Context configuration finished" } | Should -Not -BeNullOrEmpty @@ -85,7 +100,7 @@ $CommonTestCases = @( param($TestSetup, $TestType, $SentryEvent, $RunResult) if ($TestType -eq "crash-capture") { - Set-ItResult -Skipped -Because "app context is not synced to sentry-native on Android" + Set-ItResult -Skipped -Because "app context may not be available for native crashes" return } @@ -106,6 +121,11 @@ $CommonTestCases = @( @{ Name = "Contains Unity context"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) + if ($TestType -eq "crash-capture") { + Set-ItResult -Skipped -Because "Unity context may not be synchronized to NDK for native crashes" + return + } + $SentryEvent.contexts.unity | Should -Not -BeNullOrEmpty } } From 2278df05ad77d28da9b148ab2d218c0cad6a0388 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 19 Feb 2026 14:51:59 +0100 Subject: [PATCH 07/10] Extending the tests of scope sync to the crash tests --- test/IntegrationTest/CommonTestCases.ps1 | 25 ------------------------ 1 file changed, 25 deletions(-) diff --git a/test/IntegrationTest/CommonTestCases.ps1 b/test/IntegrationTest/CommonTestCases.ps1 index 581a32d60..682471972 100644 --- a/test/IntegrationTest/CommonTestCases.ps1 +++ b/test/IntegrationTest/CommonTestCases.ps1 @@ -53,11 +53,6 @@ $CommonTestCases = @( @{ Name = "Contains user information"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) - if ($TestType -eq "crash-capture") { - Set-ItResult -Skipped -Because "user context may not survive native crashes" - return - } - $SentryEvent.user | Should -Not -BeNullOrEmpty $SentryEvent.user.username | Should -Be "TestUser" $SentryEvent.user.email | Should -Be "user-mail@test.abc" @@ -67,11 +62,6 @@ $CommonTestCases = @( @{ Name = "Contains breadcrumbs"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) - if ($TestType -eq "crash-capture") { - Set-ItResult -Skipped -Because "breadcrumbs may not survive native crashes" - return - } - $SentryEvent.breadcrumbs | Should -Not -BeNullOrEmpty $SentryEvent.breadcrumbs.values | Should -Not -BeNullOrEmpty } @@ -79,11 +69,6 @@ $CommonTestCases = @( @{ Name = "Contains expected breadcrumbs"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) - if ($TestType -eq "crash-capture") { - Set-ItResult -Skipped -Because "breadcrumbs may not survive native crashes" - return - } - $SentryEvent.breadcrumbs.values | Should -Not -BeNullOrEmpty $SentryEvent.breadcrumbs.values | Where-Object { $_.message -eq "Integration test started" } | Should -Not -BeNullOrEmpty $SentryEvent.breadcrumbs.values | Where-Object { $_.message -eq "Context configuration finished" } | Should -Not -BeNullOrEmpty @@ -99,11 +84,6 @@ $CommonTestCases = @( @{ Name = "Contains app context"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) - if ($TestType -eq "crash-capture") { - Set-ItResult -Skipped -Because "app context may not be available for native crashes" - return - } - $SentryEvent.contexts.app | Should -Not -BeNullOrEmpty } } @@ -121,11 +101,6 @@ $CommonTestCases = @( @{ Name = "Contains Unity context"; TestBlock = { param($TestSetup, $TestType, $SentryEvent, $RunResult) - if ($TestType -eq "crash-capture") { - Set-ItResult -Skipped -Because "Unity context may not be synchronized to NDK for native crashes" - return - } - $SentryEvent.contexts.unity | Should -Not -BeNullOrEmpty } } From c9537e90c9e30ad6c195df8e451d262218e99342 Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 19 Feb 2026 15:44:11 +0100 Subject: [PATCH 08/10] . --- src/Sentry.Unity.Android/SentryJava.cs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Sentry.Unity.Android/SentryJava.cs b/src/Sentry.Unity.Android/SentryJava.cs index 883bdc2aa..778b3a848 100644 --- a/src/Sentry.Unity.Android/SentryJava.cs +++ b/src/Sentry.Unity.Android/SentryJava.cs @@ -107,8 +107,8 @@ public void Init(SentryUnityOptions options) try { using var sentry = new AndroidJavaClass("io.sentry.android.core.SentryAndroid"); - using var context = new AndroidJavaClass("com.unity3d.player.UnityPlayer") - .GetStatic("currentActivity"); + using var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); + using var context = unityPlayer.GetStatic("currentActivity"); sentry.CallStatic("init", context, new AndroidOptionsConfiguration(androidOptions => { @@ -118,9 +118,9 @@ public void Init(SentryUnityOptions options) androidOptions.Call("setDist", options.Distribution); androidOptions.Call("setEnvironment", options.Environment); - var sentryLevelClass = new AndroidJavaClass("io.sentry.SentryLevel"); + using var sentryLevelClass = new AndroidJavaClass("io.sentry.SentryLevel"); var levelString = GetLevelString(options.DiagnosticLevel); - var sentryLevel = sentryLevelClass.GetStatic(levelString); + using var sentryLevel = sentryLevelClass.GetStatic(levelString); androidOptions.Call("setDiagnosticLevel", sentryLevel); if (options.SampleRate.HasValue) @@ -253,7 +253,7 @@ public bool IsSentryJavaPresent() { try { - _ = GetSentryJava(); + using var _ = GetSentryJava(); } catch (AndroidJavaException) { @@ -373,9 +373,9 @@ internal void RunJniSafe(Action action, [CallerMemberName] string actionName = " { action.Invoke(); } - catch (Exception) + catch (Exception e) { - _logger?.LogError("Calling '{0}' failed.", actionName); + _logger?.LogError(e, "Calling '{0}' failed.", actionName); } } else @@ -409,9 +409,9 @@ private void SyncScope() { action.Invoke(); } - catch (Exception) + catch (Exception e) { - _logger?.LogError("Calling '{0}' failed.", actionName); + _logger?.LogError(e, "Calling '{0}' failed.", actionName); } } } @@ -436,7 +436,8 @@ public void Close() if (!MainThreadData.IsMainThread()) { - _logger?.LogError("Calling Close() on Android SDK requires running on MainThread"); + _logger?.LogError("Calling Close() on Android SDK requires running on MainThread. " + + "Scope sync thread stopped but Java SDK was not closed."); return; } From d4bb6d2eb0de14f723f6004bb5bfaf416da06c3b Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 26 Feb 2026 13:10:01 +0100 Subject: [PATCH 09/10] Detect Android activity via dumpsys, remove fallback logic --- scripts/smoke-test-android.ps1 | 36 ++++++++-------------- test/IntegrationTest/Integration.Tests.ps1 | 14 +-------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/scripts/smoke-test-android.ps1 b/scripts/smoke-test-android.ps1 index cfb778b1b..b4ce7b422 100644 --- a/scripts/smoke-test-android.ps1 +++ b/scripts/smoke-test-android.ps1 @@ -25,8 +25,7 @@ Write-Host "#####################################################" $BuildDir = $(GetNewProjectBuildPath) $ApkFileName = "test.apk" $ProcessName = "io.sentry.unity.integrationtest" -$TestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerActivity" -$FallBackTestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerGameActivity" +$TestActivityName = $null # Detected after install via dumpsys $_ArtifactsPath = (Test-Path env:ARTIFACTS_PATH) ? $env:ARTIFACTS_PATH : (Join-Path $BuildDir "../test-artifacts/" $(Get-Date -Format "HHmmss")) @@ -199,6 +198,15 @@ else return 1 } +# Detect the launcher activity from the installed package +$dumpOutput = adb -s $device shell dumpsys package $ProcessName 2>&1 | Out-String +if ($dumpOutput -match "com.unity3d.player.UnityPlayerGameActivity") { + $TestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerGameActivity" +} else { + $TestActivityName = "$ProcessName/com.unity3d.player.UnityPlayerActivity" +} +Write-Log "Detected activity: $TestActivityName" + function ProcessNewLogs([array]$newLogs, [ref]$lastLogCount, [array]$logCache) { if ($newLogs) { $currentLogs = @($newLogs) # Force array creation even for single line @@ -227,21 +235,19 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin adb -s $device shell am force-stop $ProcessName Start-Sleep -Milliseconds 500 - $activityName = $TestActivityName - Write-Log "Setting configuration" # Mark the full-screen notification as acknowledged adb -s $device shell "settings put secure immersive_mode_confirmations confirmed" adb -s $device shell "input keyevent KEYCODE_HOME" - Write-Log "Starting app '$activityName'" + Write-Log "Starting app '$TestActivityName'" # Start the adb command as a background job so we can wait for it to finish with a timeout $job = Start-Job -ScriptBlock { param($device, $activityName, $Name) & adb -s $device shell am start -n $activityName -e test $Name -W 2>&1 - } -ArgumentList $device, $activityName, $Name + } -ArgumentList $device, $TestActivityName, $Name # Wait for the job to complete or to timeout $completed = Wait-Job $job -Timeout 60 @@ -255,24 +261,6 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin $output = Receive-Job $job Remove-Job $job - Write-Log "Checking if activity started" - - # Check if the activity failed to start - if ($output -match "Error type 3" -or $output -match "Activity class \{$activityName\} does not exist.") - { - $activityName = $FallBackTestActivityName - Write-Log "Trying fallback activity $activityName" - - $output = & adb -s $device shell am start -n $activityName -e test $Name -W 2>&1 - - # Check if the fallback activity failed to start - if ($output -match "Error type 3" -or $output -match "Activity class \{$activityName\} does not exist.") - { - Write-Log "Activity does not exist" - return $false - } - } - Write-Log "Activity started successfully" $appPID = PidOf $device $ProcessName diff --git a/test/IntegrationTest/Integration.Tests.ps1 b/test/IntegrationTest/Integration.Tests.ps1 index 8fb361e3e..dc36f22c0 100644 --- a/test/IntegrationTest/Integration.Tests.ps1 +++ b/test/IntegrationTest/Integration.Tests.ps1 @@ -31,19 +31,7 @@ BeforeAll { $extras = @("-e", "test", $Action) - try { - $runResult = Invoke-DeviceApp -ExecutablePath $script:AndroidComponent -Arguments $extras - } - catch { - if ($_.Exception.Message -match "Activity class .* does not exist" -or $_.Exception.Message -match "Error type 3") { - Write-Host "Activity not found, trying fallback: $($script:FallbackAndroidComponent)" - $script:AndroidComponent = $script:FallbackAndroidComponent - $runResult = Invoke-DeviceApp -ExecutablePath $script:AndroidComponent -Arguments $extras - } - else { - throw - } - } + $runResult = Invoke-DeviceApp -ExecutablePath $script:AndroidComponent -Arguments $extras # Save result to JSON file $runResult | ConvertTo-Json -Depth 5 | Out-File -FilePath (Get-OutputFilePath "${Action}-result.json") From c7762404f3c46948bf3b526482f0898d3cb5b04c Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 26 Feb 2026 13:42:57 +0100 Subject: [PATCH 10/10] Remove dead store in smoke-test-android.ps1 --- scripts/smoke-test-android.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/smoke-test-android.ps1 b/scripts/smoke-test-android.ps1 index b4ce7b422..260ac2988 100644 --- a/scripts/smoke-test-android.ps1 +++ b/scripts/smoke-test-android.ps1 @@ -258,7 +258,7 @@ function RunTest([string] $Name, [string] $SuccessString, [string] $FailureStrin return $false } - $output = Receive-Job $job + Receive-Job $job | Out-Null Remove-Job $job Write-Log "Activity started successfully"