From 1371587ff0e56173ad57b49bb72f3fea141a416b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 15 Sep 2026 14:34:32 +0200 Subject: [PATCH] build(switch): prepare stubs before batch builds Fresh Switch integration builds with no-op stubs fail with `BuildFailedException`: Sentry's Switch no-op stubs in 'Assets/Plugins/Sentry' were out of step with the installed libraries and have been updated. Please trigger the build again. Fresh integration projects reached `BuildPlayer` without the Switch no-op stub. Stub setup was deferred through `EditorApplication.delayCall` and only created files for the active build target, but the batch build did not select Switch at startup. The build preprocessor copied the missing stub and then deliberately failed: Unity collects native plugins before preprocessing, so adding one there cannot reliably affect the current build. Starting another CI run with a clean project repeats the same failure. Select Switch with `-buildTarget` when launching the integration build. Synchronize stubs directly in `OnPostprocessAllAssets` after domain reloads or native library changes, when asset operations are safe. This prepares the stub before building and removes it when the real native libraries are imported. --- src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs | 10 ++++------ test/Scripts.Integration.Test/build-project.ps1 | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs b/src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs index 50b2b7e4c..a9966f4d8 100644 --- a/src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs +++ b/src/Sentry.Unity.Editor/Native/SwitchNativeStub.cs @@ -75,9 +75,6 @@ private static bool Matches(string stub, string template) => private static string Normalize(string content) => content.Replace("\r\n", "\n").Replace("\r", "\n").TrimEnd(); - [InitializeOnLoadMethod] - private static void OnDomainReload() => EditorApplication.delayCall += () => Sync(null); - /// /// Syncs the SDK with the state of the game. Adds/removes the stub. /// @@ -213,7 +210,8 @@ private static string TemplatePath() => Path.GetFullPath(Path.Combine( internal class SwitchNativeStubWatcher : AssetPostprocessor { private static void OnPostprocessAllAssets( - string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) + string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, + bool didDomainReload) { var librariesChanged = importedAssets .Concat(deletedAssets) @@ -222,9 +220,9 @@ private static void OnPostprocessAllAssets( .Any(path => SwitchNativeStub.LibraryFileNames.Any( library => path.EndsWith(library, StringComparison.Ordinal))); - if (librariesChanged) + if (didDomainReload || librariesChanged) { - EditorApplication.delayCall += () => SwitchNativeStub.Sync(null); + SwitchNativeStub.Sync(null); } } } diff --git a/test/Scripts.Integration.Test/build-project.ps1 b/test/Scripts.Integration.Test/build-project.ps1 index 35a287637..01a0e5902 100644 --- a/test/Scripts.Integration.Test/build-project.ps1 +++ b/test/Scripts.Integration.Test/build-project.ps1 @@ -21,6 +21,11 @@ Write-Log "Build method: $buildMethod" Write-Detail "Output path: $outputPath" $unityArgs = @("-batchmode", "-projectPath ", "$(GetNewProjectPath)", "-executeMethod", $buildMethod , "-buildPath", $outputPath, "-quit") +if ($Platform -eq "Switch") +{ + $unityArgs += @("-buildTarget", "Switch") +} + RunUnityCustom $unityPath $unityArgs if ($Platform -eq "Android-Export")