Skip to content

Commit a888dde

Browse files
Detect Sentry Java SDK dependencies during build (#4079)
1 parent 35254c0 commit a888dde

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Sentry Java SDK dependencies are now detected and included in the Android bindings ([#4079](https://github.com/getsentry/sentry-dotnet/pull/4079))
8+
39
## 5.5.0
410

511
### Features

src/Sentry.Bindings.Android/Sentry.Bindings.Android.csproj

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net8.0-android34.0</TargetFrameworks>
4-
<!-- BG8605 and BG8606 happen because there's a missing androidx.lifecycle dependency, but we don't need it here. (The native Android Sentry SDK will use it if it exists.) -->
5-
<NoWarn>$(NoWarn);BG8605;BG8606</NoWarn>
3+
<TargetFrameworks>net8.0-android34.0;net9.0-android35.0</TargetFrameworks>
64
<SentryAndroidSdkVersion>8.6.0</SentryAndroidSdkVersion>
7-
<SentryAndroidSdkDirectory>$(BaseIntermediateOutputPath)sdks\Sentry\Android\$(SentryAndroidSdkVersion)\</SentryAndroidSdkDirectory>
5+
<SentryAndroidSdkDirectory>$(BaseIntermediateOutputPath)sdks\$(TargetFramework)\Sentry\Android\$(SentryAndroidSdkVersion)\</SentryAndroidSdkDirectory>
86
<!-- This gets resolved by the DownloadSentryAndroidSdk target -->
97
<SentryNativeNdkVersion></SentryNativeNdkVersion>
108
<Description>.NET Bindings for the Sentry Android SDK</Description>
@@ -31,10 +29,46 @@
3129
<InternalsVisibleTo Include="Sentry.Maui.Tests" PublicKey="$(SentryPublicKey)" />
3230
</ItemGroup>
3331

34-
<ItemGroup>
32+
<!-- Dependencies for AndroidMavenLibrary references
33+
Note: versions match what was shipped with net8.0-android34.0 in:
34+
https://www.nuget.org/packages/Microsoft.Maui.Core/8.0.3#dependencies-body-tab
35+
-->
36+
<ItemGroup Condition="$(TargetFramework.StartsWith('net8'))">
37+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Process" Version="2.6.1.3" />
38+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common.Java8" Version="2.6.1.3" />
39+
<!-- MAUI 8 references this version indirectly via Xamarin.AndroidX.SwipeRefreshLayout (>= 1.1.0.14) -->
40+
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.10.1.2" />
41+
</ItemGroup>
42+
43+
<!-- Dependencies for AndroidMavenLibrary references
44+
Note: versions match what was shipped with net9.0-android35.0 in:
45+
https://www.nuget.org/packages/Microsoft.Maui.Core/9.0.0#dependencies-body-tab
46+
-->
47+
<ItemGroup Condition="$(TargetFramework.StartsWith('net9'))">
48+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Process" Version="2.8.5.1" />
49+
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common.Java8" Version="2.8.5.1" />
50+
<!-- MAUI 9 references this version indirectly via Xamarin.AndroidX.SwipeRefreshLayout (>= 1.1.0.24) -->
51+
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.13.1.5" />
52+
</ItemGroup>
53+
54+
<ItemGroup Condition="$(TargetFramework.StartsWith('net8'))">
3555
<AndroidLibrary Include="$(SentryAndroidSdkDirectory)sentry-$(SentryAndroidSdkVersion).jar" />
3656
<AndroidLibrary Include="$(SentryAndroidSdkDirectory)sentry-android-core-$(SentryAndroidSdkVersion).aar" />
3757
<AndroidLibrary Include="$(SentryAndroidSdkDirectory)sentry-android-ndk-$(SentryAndroidSdkVersion).aar" />
58+
</ItemGroup>
59+
60+
<!-- Starting with .NET 9 we can detect Java dependencies using POM files and AndroidMavenLibrary references -->
61+
<ItemGroup Condition="!$(TargetFramework.StartsWith('net8'))">
62+
<AndroidLibrary
63+
Include="$(SentryAndroidSdkDirectory)sentry-$(SentryAndroidSdkVersion).jar"
64+
Manifest="$(SentryAndroidSdkDirectory)sentry-$(SentryAndroidSdkVersion).pom"
65+
JavaArtifact="io.sentry:sentry:$(SentryAndroidSdkVersion)"
66+
/>
67+
<AndroidMavenLibrary Include="io.sentry:sentry-android-core" Version="$(SentryAndroidSdkVersion)" />
68+
<AndroidMavenLibrary Include="io.sentry:sentry-android-ndk" Version="$(SentryAndroidSdkVersion)" />
69+
</ItemGroup>
70+
71+
<ItemGroup>
3872
<AndroidLibrary Include="..\..\lib\sentry-android-supplemental\bin\sentry-android-supplemental.jar" />
3973
<AndroidNativeLibrary Include="..\..\lib\sentrysupplemental\bin\arm64-v8a\libsentrysupplemental.so" Abi="arm64-v8a" />
4074
<AndroidNativeLibrary Include="..\..\lib\sentrysupplemental\bin\armeabi-v7a\libsentrysupplemental.so" Abi="armeabi-v7a" />
@@ -46,13 +80,13 @@
4680
<DownloadFile
4781
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry-android-core/$(SentryAndroidSdkVersion)/sentry-android-core-$(SentryAndroidSdkVersion).aar"
4882
DestinationFolder="$(SentryAndroidSdkDirectory)"
49-
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-android-core-$(SentryAndroidSdkVersion).aar')"
83+
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-android-core-$(SentryAndroidSdkVersion).aar') And $(TargetFramework.StartsWith('net8'))"
5084
Retries="3"
5185
/>
5286
<DownloadFile
5387
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry-android-ndk/$(SentryAndroidSdkVersion)/sentry-android-ndk-$(SentryAndroidSdkVersion).aar"
5488
DestinationFolder="$(SentryAndroidSdkDirectory)"
55-
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-android-ndk-$(SentryAndroidSdkVersion).aar')"
89+
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-android-ndk-$(SentryAndroidSdkVersion).aar') And $(TargetFramework.StartsWith('net8'))"
5690
Retries="3"
5791
/>
5892
<DownloadFile
@@ -61,32 +95,41 @@
6195
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-$(SentryAndroidSdkVersion).jar')"
6296
Retries="3"
6397
/>
98+
<DownloadFile
99+
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry/$(SentryAndroidSdkVersion)/sentry-$(SentryAndroidSdkVersion).pom"
100+
DestinationFolder="$(SentryAndroidSdkDirectory)"
101+
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-$(SentryAndroidSdkVersion).pom') And !$(TargetFramework.StartsWith('net8'))"
102+
Retries="3"
103+
/>
104+
64105
<!-- The native-ndk exists outside of the android-ndk now. We're downloading the POM file to get the version of the native-ndk. -->
65106
<DownloadFile
66107
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry-android-ndk/$(SentryAndroidSdkVersion)/sentry-android-ndk-$(SentryAndroidSdkVersion).pom"
67108
DestinationFolder="$(SentryAndroidSdkDirectory)"
68109
Condition="!Exists('$(SentryAndroidSdkDirectory)sentry-android-ndk-$(SentryAndroidSdkVersion).pom')"
69110
Retries="3"
70111
/>
71-
112+
72113
<XmlPeek
73114
XmlInputPath="$(SentryAndroidSdkDirectory)sentry-android-ndk-$(SentryAndroidSdkVersion).pom"
74115
Query="//*[local-name()='dependency' and .//*[local-name()='artifactId' and text()='sentry-native-ndk']]/*[local-name()='version']/text()"
75116
Condition="Exists('$(SentryAndroidSdkDirectory)sentry-android-ndk-$(SentryAndroidSdkVersion).pom')">
76117
<Output TaskParameter="Result" PropertyName="SentryNativeNdkVersion" />
77118
</XmlPeek>
78-
119+
79120
<DownloadFile
80121
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry-native-ndk/$(SentryNativeNdkVersion)/sentry-native-ndk-$(SentryNativeNdkVersion).aar"
81122
DestinationFolder="$(SentryAndroidSdkDirectory)"
82-
Condition="'$(SentryNativeNdkVersion)' != '' And !Exists('$(SentryAndroidSdkDirectory)sentry-native-ndk-$(SentryNativeNdkVersion).aar')"
123+
Condition="'$(SentryNativeNdkVersion)' != '' And !Exists('$(SentryAndroidSdkDirectory)sentry-native-ndk-$(SentryNativeNdkVersion).aar') And $(TargetFramework.StartsWith('net8'))"
83124
Retries="3"
84125
/>
85-
86-
<!-- Since we're reading the version from the POM file, we need to create an item for the downloaded sentry-native-ndk -->
87-
<ItemGroup Condition="'$(SentryNativeNdkVersion)' != ''">
126+
127+
<ItemGroup Condition="'$(SentryNativeNdkVersion)' != '' And $(TargetFramework.StartsWith('net8'))">
88128
<AndroidLibrary Include="$(SentryAndroidSdkDirectory)sentry-native-ndk-$(SentryNativeNdkVersion).aar" />
89129
</ItemGroup>
130+
<ItemGroup Condition="'$(SentryNativeNdkVersion)' != '' And !$(TargetFramework.StartsWith('net8'))">
131+
<AndroidMavenLibrary Include="io.sentry:sentry-native-ndk" Version="$(SentryNativeNdkVersion)" />
132+
</ItemGroup>
90133
</Target>
91134

92135
<UsingTask TaskName="XmlPeek" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

0 commit comments

Comments
 (0)