Skip to content

Detect Sentry Java SDK dependencies during build #4079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 7, 2025

Conversation

jamescrosswell
Copy link
Collaborator

@jamescrosswell jamescrosswell commented Apr 3, 2025

Resolves Java dependencies for all of the existing Maven repositories we depend on.

Relates to:

To fix that particular issue, we need to add an AndroidMavenLibrary reference to the sentry-android-replay ArtefactId when implementing:

Summary

.NET 9 adds some features that allow us to detect Java dependencies, with build warnings for any that are missing 🎉

Previously we downloaded java/aar files for Sentry's Java SDK from Maven and then referenced these directly with AndroidLibrary XML tags. The new features in .NET 9 allow us to include a Manifest/POM file when referencing *.java files (the POM file is what describes the dependencies of the java library) or to reference maven repositories directly with AndroidMavenLibrary tags which takes care of downloading the java and POM files and referencing these.

Solution

For all of this to work, Sentry.Bindings.Android.csproj has to target net9.0-android. So I've added a net9 target and it turns out we were missing various dependencies:

1>Xamarin.Android.Bindings.JavaDependencyVerification.targets(27,5): Error XA4242 : Java dependency 'androidx.lifecycle:lifecycle-process:2.2.0' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.AndroidX.Lifecycle.Process' that could fulfill this dependency.
1>Xamarin.Android.Bindings.JavaDependencyVerification.targets(27,5): Error XA4242 : Java dependency 'androidx.lifecycle:lifecycle-common-java8:2.2.0' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.AndroidX.Lifecycle.Common.Java8' that could fulfill this dependency.
1>Xamarin.Android.Bindings.JavaDependencyVerification.targets(27,5): Error XA4242 : Java dependency 'androidx.core:core:1.3.2' is not satisfied. Microsoft maintains the NuGet package 'Xamarin.AndroidX.Core' that could fulfill this dependency.

Although the tooling only identifies these when targeting net9, I believe we were missing the same dependencies when targeting net8.0. This may explain various "missing class" errors that users have been reporting at runtime.

In addition to adding the tooling to ensure we get appropriate warnings then, this PR also includes appropriate versions of the missing libraries.

References

@jamescrosswell jamescrosswell marked this pull request as ready for review April 4, 2025 07:47
@bitsandfoxes
Copy link
Contributor

bitsandfoxes commented Apr 4, 2025

I've got this one ready to go #4075
Which ever one of us gets to merge first? 😅

@jamescrosswell
Copy link
Collaborator Author

jamescrosswell commented Apr 6, 2025

I've got this one ready to go #4075 Which ever one of us gets to merge first? 😅

Interesting. Thanks heaps for bumping to 8.x!

TLDR; I think we need both PRs so will just have to deal with merge conflicts.

Full explanation, this PR doesn't bump the version at all. It exists to detect and add missing Java dependencies:

<!-- Dependencies for AndroidMavenLibrary references -->
<!-- Note: versions match what was shipped with net8.0-android34.0 in MAUI -->
<ItemGroup Condition="$(TargetFramework.StartsWith('net8'))">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Process" Version="2.6.1.3" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common.Java8" Version="2.6.1.3" />
<!-- MAUI 8 references this version indirectly via Xamarin.AndroidX.SwipeRefreshLayout (>= 1.1.0.14) -->
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.10.1.2" />
</ItemGroup>
<!-- Dependencies for AndroidMavenLibrary references -->
<!-- Note: versions match what was shipped with net9.0-android35.0 in MAUI -->
<ItemGroup Condition="$(TargetFramework.StartsWith('net9'))">
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Process" Version="2.8.5.1" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.Common.Java8" Version="2.8.5.1" />
<!-- MAUI 9 references this version indirectly via Xamarin.AndroidX.SwipeRefreshLayout (>= 1.1.0.24) -->
<PackageReference Include="Xamarin.AndroidX.Core" Version="1.13.1.5" />
</ItemGroup>

The tooling that uses the POM files to create errors for missing java dependencies was only added in net9.0 so I had to add a net9.0 target to get the errors... then trawl the net9.0-android dependencies for MAUI core to identify the appropriate minimum versions for these.

@jamescrosswell jamescrosswell marked this pull request as draft April 6, 2025 21:52
@jamescrosswell jamescrosswell marked this pull request as ready for review April 7, 2025 00:38
@jamescrosswell jamescrosswell merged commit a888dde into main Apr 7, 2025
27 checks passed
@jamescrosswell jamescrosswell deleted the android-maven-library branch April 7, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants