Skip to content

Conversation

@jamescrosswell
Copy link
Collaborator

@jamescrosswell jamescrosswell commented Mar 13, 2025

Closes #3761:

Fixes #3983:

Fixes #3985:

Summary

.NET 9 does introduced a new AssemblyStore format for APK files. Reading the new format is demonstrated in assembly-store-reader-mk2. This PR adds support for reading the new format to the AndroidAssemblyReaderFactory.

Also, the reason we didn't pick this up when we moved to net9.0 is that the device tests are/were only running against net8.0 targets. In this PR we'll try to run the device tests on net8.0-android/ios and net9.0-android/ios.

Notes for Reviewers

There's a lot of code here. However most of it is simply copied/vendored in from two external repositories.

ELFSharp

For the purposes of review, you can ignore all of the files in the "src/Sentry.Android.AssemblyReader/ELFSharp" folder.

The V2 format for APKs stores all assemblies in in an RID specific folder but Android requires all files in that folder to be ELF files... so during the build process any exe, dll, pdb or config files stored in there get "packed" into ELF files... we need to use ElfSharp to unpack these.

To avoid adding any dependencies, the code for ELFSharp has been copied in to the Sentry.Android.AssemblyReader project (with appropriate attribution).

dotnet/android

For the purposes of review, you can ignore most of the files in the "src/Sentry.Android.AssemblyReader/V2" folder.

src/Sentry.Android.AssemblyReader/V2/AndroidAssemblyStoreReaderV2.cs and AndroidAssemblyDirectoryReaderV2 are classes I wrote (although AndroidAssemblyDirectoryReaderV2.ArchiveAssemblyHelper was vendored in). Otherwise, all of the files in src/Sentry.Android.AssemblyReader/V2 have been copied from the dotnet/android repo, with appropriate attribution at the top of each file.

No functional changes were made to any of that code. The only alterations were:

  • Visibility changed from public to internal
  • Unused code from files that we vendored in has been removed
  • I removed the dependency on Xamarin.LibZipSharp (using the built in ZipFile class instead)
  • A little bit of Ctrl + . in resharper to get the code to conform to our coding conventions

References

Relates to:

@vaind
Copy link
Contributor

vaind commented Mar 21, 2025

With all the vendored-in code this is pretty hard to review. Can you link a diff showing your changes to the vendored code?

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just skimmed this change. Ideally someone can do a proper review

$tfm = 'net8.0-'
if (!$Tfm)
{
$Tfm = 'net8.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once we clear all callsites to pass a tfm, we should delete this and throw an error instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a default argument, if you don't specify a target framework. We could try to change the default to latest or something like that - would need a little bit of extra scripting to work out what latest was.

#endif
using var sut = GetSut(isAssemblyStore, isCompressed: true);
if (isAssemblyStore)
using var sut = GetSut(false, true, isCompressed: true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using var sut = GetSut(false, true, isCompressed: true);
using var sut = GetSut(isAot: false, isAssemblyStore: true, isCompressed: true);

#if ANDROID
Skip.If(true, "It's unknown whether the current Android app APK is an assembly store or not.");
#endif
using var sut = GetSut(false, false, isCompressed: true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using var sut = GetSut(false, false, isCompressed: true);
using var sut = GetSut(isAot: false, isAssemblyStore: false, isCompressed: true);

public void ReturnsNullIfAssemblyDoesntExist(bool isAssemblyStore)
{
using var sut = GetSut(isAssemblyStore, isCompressed: true);
using var sut = GetSut(false, isAssemblyStore, isCompressed: true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using var sut = GetSut(false, isAssemblyStore, isCompressed: true);
using var sut = GetSut(isAot: false, isAssemblyStore, isCompressed: true);

@jamescrosswell jamescrosswell merged commit 13d4a9f into main Apr 2, 2025
26 checks passed
@jamescrosswell jamescrosswell deleted the store-v2 branch April 2, 2025 06:31
ShortDevelopment added a commit to nearby-sharing/android that referenced this pull request Apr 6, 2025
Should fix `net-9.0` symbolication on android
getsentry/sentry-dotnet#4033
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants