Skip to content

Commit ba47ffa

Browse files
chore: Allow Android bindings to be built using local maven artefacts (#4873)
1 parent b1dbd13 commit ba47ffa

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

CONTRIBUTING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,20 @@ and let the next build download the pre-built SDK again:
194194
$ rm -rf modules/sentry-cocoa
195195
$ dotnet build ... # downloads pre-built Cocoa SDK into modules/sentry-cocoa
196196
```
197+
198+
## Local Sentry Android SDK checkout
199+
200+
Similarly, by default, `Sentry.Bindings.Android` downloads a pre-built Sentry Android SDK from
201+
Maven. The version is specified in the `SentryAndroidSdkVersion` build property in `Sentry.Bindings.Android.csproj`.
202+
203+
If you want to build an unreleased Sentry Android SDK version from source instead,
204+
you'll need to clone both the sentry-java and the sentry-native repositories and publish these locally:
205+
```sh
206+
$ cd $(LocalSentryJavaRepoDir) && ./gradlew publishToMavenLocal
207+
$ cd $(LocalSentryNativeRepoDir)/ndk && ./gradlew publishToMavenLocal
208+
```
209+
210+
You'll also need to set `<UseLocalSentryMavenRepo>true</UseLocalSentryMavenRepo>` and `<SentryNativeNdkVersion>{whatever_version_you_checked_out}</SentryNativeNdkVersion>`
211+
in the `Sentry.Bindings.Android.csproj`file.
212+
213+
To switch back again, simply revert those two build properties to their original values.

src/Sentry.Bindings.Android/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Instead, reference one of the following:
66

77
## SDK Developers and Contributors
88

9-
For .NET SDK contributors, most of the classes in this package are generated automatically.
9+
For .NET SDK contributors, most of the classes in this package are generated automatically. These can be found in the `src/Sentry.Bindings.Android/obj/{Configuration}/{tfm}/generated/src/` folder after building the project.
1010

1111
- Post generation transformations are controlled via various XML files stored in the `/Transforms` directory (see [Java Bindings Metadata documentation](https://learn.microsoft.com/en-gb/previous-versions/xamarin/android/platform/binding-java-library/customizing-bindings/java-bindings-metadata) for details).
1212

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

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,37 @@
33
<TargetFrameworks>$(LatestAndroidTfm);$(PreviousAndroidTfm)</TargetFrameworks>
44
<SentryAndroidSdkVersion>8.29.0</SentryAndroidSdkVersion>
55
<SentryAndroidSdkDirectory>$(BaseIntermediateOutputPath)sdks\$(TargetFramework)\Sentry\Android\$(SentryAndroidSdkVersion)\</SentryAndroidSdkDirectory>
6-
<!-- This gets resolved by the DownloadSentryAndroidSdk target -->
6+
<!-- This gets resolved by the DownloadSentryAndroidSdk unless using local maven references -->
77
<SentryNativeNdkVersion></SentryNativeNdkVersion>
88
<Description>.NET Bindings for the Sentry Android SDK</Description>
99

10+
<!--
11+
Optional dev override: enable to resolve local maven references
12+
Example:
13+
dotnet build -p:UseLocalSentryMavenRepo=true
14+
15+
To populate MavenLocal from your checkout:
16+
cd $(LocalSentryJavaRepoDir) && ./gradlew publishToMavenLocal
17+
cd $(LocalSentryNativeRepoDir)/ndk && ./gradlew publishToMavenLocal
18+
19+
Note:
20+
1. Make sure the native-ndk-version you check out and build matches what the android sdk expects (or a fork of it)
21+
2. You will need to manually set the `SentryNativeNdkVersion` property as this no longer gets resolved from
22+
the POM files from the Java SDK when using local maven artifacts.
23+
-->
24+
<UseLocalSentryMavenRepo>false</UseLocalSentryMavenRepo>
25+
<LocalSentryMavenRepoDir Condition="'$(LocalSentryMavenRepoDir)' == ''">$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))/.m2/repository/</LocalSentryMavenRepoDir>
26+
<LocalSentryJarPath>$(LocalSentryMavenRepoDir)io/sentry/sentry/$(SentryAndroidSdkVersion)/sentry-$(SentryAndroidSdkVersion).jar</LocalSentryJarPath>
27+
<LocalSentryAndroidCoreAarPath>$(LocalSentryMavenRepoDir)io/sentry/sentry-android-core/$(SentryAndroidSdkVersion)/sentry-android-core-$(SentryAndroidSdkVersion).aar</LocalSentryAndroidCoreAarPath>
28+
<LocalSentryAndroidNdkAarPath>$(LocalSentryMavenRepoDir)io/sentry/sentry-android-ndk/$(SentryAndroidSdkVersion)/sentry-android-ndk-$(SentryAndroidSdkVersion).aar</LocalSentryAndroidNdkAarPath>
29+
<LocalSentryAndroidReplayAarPath>$(LocalSentryMavenRepoDir)io/sentry/sentry-android-replay/$(SentryAndroidSdkVersion)/sentry-android-replay-$(SentryAndroidSdkVersion).aar</LocalSentryAndroidReplayAarPath>
30+
<LocalSentryPomPath>$([System.String]::Copy($(LocalSentryJarPath)).Replace('.jar', '.pom'))</LocalSentryPomPath>
31+
<LocalSentryAndroidCorePomPath>$([System.String]::Copy($(LocalSentryAndroidCoreAarPath)).Replace('.aar', '.pom'))</LocalSentryAndroidCorePomPath>
32+
<LocalSentryAndroidNdkPomPath>$([System.String]::Copy($(LocalSentryAndroidNdkAarPath)).Replace('.aar', '.pom'))</LocalSentryAndroidNdkPomPath>
33+
<LocalSentryAndroidReplayPomPath>$([System.String]::Copy($(LocalSentryAndroidReplayAarPath)).Replace('.aar', '.pom'))</LocalSentryAndroidReplayPomPath>
34+
<LocalSentryNativeNdkAarPath>$(LocalSentryMavenRepoDir)io/sentry/sentry-native-ndk/$(SentryNativeNdkVersion)/sentry-native-ndk-$(SentryNativeNdkVersion).aar</LocalSentryNativeNdkAarPath>
35+
<LocalSentryNativeNdkPomPath>$([System.String]::Copy($(LocalSentryNativeNdkAarPath)).Replace('.aar', '.pom'))</LocalSentryNativeNdkPomPath>
36+
1037
<!-- Android binding warnings - these are largely unavoidable due to Java interface circular dependencies -->
1138
<!-- Only suppress warnings that are confirmed to be expected/unavoidable -->
1239
<!-- BG8801: Invalid parameter types - caused by circular interface dependencies in Sentry Java SDK -->
@@ -73,13 +100,27 @@
73100
</ItemGroup>
74101

75102
<!-- Starting with .NET 9 we can detect Java dependencies using POM files and AndroidMavenLibrary references -->
76-
<ItemGroup>
103+
<ItemGroup Condition="'$(UseLocalSentryMavenRepo)' != 'true'">
77104
<AndroidMavenLibrary Include="io.sentry:sentry" Version="$(SentryAndroidSdkVersion)" />
78105
<AndroidMavenLibrary Include="io.sentry:sentry-android-core" Version="$(SentryAndroidSdkVersion)" />
79106
<AndroidMavenLibrary Include="io.sentry:sentry-android-ndk" Version="$(SentryAndroidSdkVersion)" />
80107
<AndroidMavenLibrary Include="io.sentry:sentry-android-replay" Version="$(SentryAndroidSdkVersion)" />
81108
</ItemGroup>
82109

110+
<!-- Resolve Java dependencies from local sentry-java build outputs instead, if appropriate -->
111+
<ItemGroup Condition="'$(UseLocalSentryMavenRepo)' == 'true'">
112+
<AndroidLibrary Include="$(LocalSentryJarPath)" Manifest="$(LocalSentryPomPath)"
113+
JavaArtifact="io.sentry:sentry:$(SentryAndroidSdkVersion)" />
114+
<AndroidLibrary Include="$(LocalSentryAndroidCoreAarPath)" Manifest="$(LocalSentryAndroidCorePomPath)"
115+
JavaArtifact="io.sentry:sentry-android-core:$(SentryAndroidSdkVersion)" />
116+
<AndroidLibrary Include="$(LocalSentryAndroidNdkAarPath)" Manifest="$(LocalSentryAndroidNdkPomPath)"
117+
JavaArtifact="io.sentry:sentry-android-ndk:$(SentryAndroidSdkVersion)" />
118+
<AndroidLibrary Include="$(LocalSentryAndroidReplayAarPath)" Manifest="$(LocalSentryAndroidReplayPomPath)"
119+
JavaArtifact="io.sentry:sentry-android-replay:$(SentryAndroidSdkVersion)" />
120+
<AndroidLibrary Include="$(LocalSentryNativeNdkAarPath)" Manifest="$(LocalSentryNativeNdkPomPath)"
121+
JavaArtifact="io.sentry:sentry-native-ndk:$(SentryNativeNdkVersion)" />
122+
</ItemGroup>
123+
83124
<ItemGroup>
84125
<AndroidLibrary Include="..\..\lib\sentry-android-supplemental\bin\sentry-android-supplemental.jar" />
85126
<AndroidNativeLibrary Include="..\..\lib\sentrysupplemental\bin\arm64-v8a\libsentrysupplemental.so" Abi="arm64-v8a" />
@@ -88,7 +129,7 @@
88129
<AndroidNativeLibrary Include="..\..\lib\sentrysupplemental\bin\x86_64\libsentrysupplemental.so" Abi="x86_64" />
89130
</ItemGroup>
90131

91-
<Target Name="DownloadSentryAndroidSdk" BeforeTargets="CollectPackageReferences">
132+
<Target Name="DownloadSentryAndroidSdk" BeforeTargets="CollectPackageReferences" Condition="'$(UseLocalSentryMavenRepo)' != 'true'">
92133
<!-- The native-ndk exists outside of the android-ndk now. We're downloading the POM file to get the version of the native-ndk. -->
93134
<DownloadFile
94135
SourceUrl="https://repo1.maven.org/maven2/io/sentry/sentry-android-ndk/$(SentryAndroidSdkVersion)/sentry-android-ndk-$(SentryAndroidSdkVersion).pom"

0 commit comments

Comments
 (0)