Skip to content

Commit 545ac31

Browse files
jpnurmiweb-flowclaude
authored
fix: prevent redundant native exceptions on Android/CoreCLR (#5127)
* chore: update scripts/update-java.ps1 to 8.39.0 * fix(android): preload NDK integration for CoreCLR Enable the io.sentry.ndk.preload metadata so that SentryNdkPreloadProvider installs sentry-native's signal handlers before .NET/CoreCLR. This ensures the correct handler chain order (.NET -> sentry-native -> debuggerd) where .NET handles managed exceptions first, and native crashes chain to sentry-native. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * clarify CoreCLR signal handler fallback log Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * scope NDK preload imports to the maui test app Keeps the source-tree Sentry.targets import out of the shared integration-test/Directory.Build.targets so non-Android integration tests (AOT, runtime, console) aren't affected. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * skip CoreCLR variants on .NET 9 Android CoreCLR support starts with .NET 10; running the coreclr cases on net9.0 would fail at build time. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: GitHub <noreply@github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8d58989 commit 545ac31

5 files changed

Lines changed: 44 additions & 4 deletions

File tree

integration-test/android.Tests.ps1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@ BeforeDiscovery {
1818
}
1919

2020
$cases = @(
21-
@{ configuration = 'Release' }
22-
@{ configuration = 'Debug' }
21+
@{ configuration = 'Release'; runtime = 'mono' }
22+
@{ configuration = 'Debug'; runtime = 'mono' }
2323
)
24-
Describe 'MAUI app (<dotnet_version>, <configuration>)' -ForEach $cases -Skip:(-not $script:emulator) {
24+
# CoreCLR on Android requires .NET 10 or later
25+
if ($dotnet_version -ne 'net9.0') {
26+
$cases += @(
27+
@{ configuration = 'Release'; runtime = 'coreclr' }
28+
@{ configuration = 'Debug'; runtime = 'coreclr' }
29+
)
30+
}
31+
Describe 'MAUI app (<dotnet_version>, <configuration>, <runtime>)' -ForEach $cases -Skip:(-not $script:emulator) {
2532
BeforeAll {
2633
$tfm = "$dotnet_version-android$(GetAndroidTpv $dotnet_version)"
2734

@@ -38,10 +45,12 @@ Describe 'MAUI app (<dotnet_version>, <configuration>)' -ForEach $cases -Skip:(-
3845
$rid = "android-$arch"
3946

4047
Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj"
48+
$useMonoRuntime = if ($runtime -eq 'mono') { 'true' } else { 'false' }
4149
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
4250
--configuration $configuration `
4351
--framework $tfm `
44-
--runtime $rid
52+
--runtime $rid `
53+
-p:UseMonoRuntime=$useMonoRuntime
4554
| ForEach-Object { Write-Host $_ }
4655
Write-Host '::endgroup::'
4756
$LASTEXITCODE | Should -Be 0

integration-test/net9-maui/Sentry.Maui.Device.IntegrationTestApp.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,10 @@
6464
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.5" />
6565
</ItemGroup>
6666

67+
<!-- Needed for SetAndroidNdkPreload (buildTransitive doesn't apply via ProjectReference) -->
68+
<ImportGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
69+
<Import Project="..\..\src\Sentry\buildTransitive\Sentry.props" Condition="Exists('..\..\src\Sentry\buildTransitive\Sentry.props')" />
70+
<Import Project="..\..\src\Sentry\buildTransitive\Sentry.targets" Condition="Exists('..\..\src\Sentry\buildTransitive\Sentry.targets')" />
71+
</ImportGroup>
72+
6773
</Project>

src/Sentry/Platforms/Android/SentrySdk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ private static void InitSentryAndroidSdk(SentryOptions options)
6666
o.ShutdownTimeoutMillis = (long)options.ShutdownTimeout.TotalMilliseconds;
6767

6868
var signalHandlerStrategy = options.Native.ExperimentalOptions.SignalHandlerStrategy;
69+
if (signalHandlerStrategy == SignalHandlerStrategy.ChainAtStart
70+
&& Type.GetType("Mono.RuntimeStructs") == null)
71+
{
72+
options.LogInfo(
73+
"Using SignalHandlerStrategy.Default on .NET CoreCLR. " +
74+
"SignalHandlerStrategy.ChainAtStart is only required on the Mono runtime.");
75+
signalHandlerStrategy = SignalHandlerStrategy.Default;
76+
}
6977
if (signalHandlerStrategy == SignalHandlerStrategy.ChainAtStart
7078
&& System.Environment.Version is { Major: 10, Minor: 0, Build: < 4 })
7179
{

src/Sentry/buildTransitive/Sentry.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
<_SentryTargetFrameworkVersion>$([MSBuild]::GetTargetFrameworkVersion($(TargetFramework)))</_SentryTargetFrameworkVersion>
66
<_SentryIsNet8OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 8.0))</_SentryIsNet8OrGreater>
77
<_SentryIsNet9OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 9.0))</_SentryIsNet9OrGreater>
8+
<_SentryIsNet10OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 10.0))</_SentryIsNet10OrGreater>
89
</PropertyGroup>
910
</Project>

src/Sentry/buildTransitive/Sentry.targets

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,22 @@
281281
</ItemGroup>
282282
</Target>
283283

284+
<!-- Preload NDK to ensure sentry-native's signal handlers are installed before .NET runtime's.
285+
Disabled on Mono until: https://github.com/dotnet/runtime/pull/125835 -->
286+
<Target Name="SetAndroidNdkPreload"
287+
BeforeTargets="GetAssemblyAttributes"
288+
Condition="'$(AndroidApplication)' == 'True'
289+
and $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'
290+
and '$(_SentryIsNet10OrGreater)' == 'true'
291+
and '$(UseMonoRuntime)' != 'true'">
292+
<ItemGroup>
293+
<AssemblyAttribute Include="Android.App.MetaData">
294+
<_Parameter1>io.sentry.ndk.preload</_Parameter1>
295+
<Value>true</Value>
296+
</AssemblyAttribute>
297+
</ItemGroup>
298+
</Target>
299+
284300
<!-- Upload Android ProGuard mapping file to Sentry after the build. -->
285301
<Target Name="UploadAndroidProGuardMappingFileToSentry" AfterTargets="Build" DependsOnTargets="PrepareSentryCLI"
286302
Condition="'$(SentryCLI)' != '' and '$(SentryUploadAndroidProGuardMapping)' == 'true' And '$(AndroidProguardMappingFile)' != ''">

0 commit comments

Comments
 (0)