Skip to content

fix: Source context for class libraries when running on Android in Release mode #4294

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

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/device-tests-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ jobs:
matrix:
tfm: [net9.0]
# We run against both an older and a newer API
api-level: [27, 33]
# targetSdk must be 34+ for new apps and app updates as of August 31, 2024.
api-level: [34, 36]
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Sentry now decompresses Request bodies in ASP.NET Core when RequestDecompression middleware is enabled ([#4315](https://github.com/getsentry/sentry-dotnet/pull/4315))
- Custom ISentryEventProcessors are now run for native iOS events ([#4318](https://github.com/getsentry/sentry-dotnet/pull/4318))
- Crontab validation when capturing checkins ([#4314](https://github.com/getsentry/sentry-dotnet/pull/4314))
- Source context for class libraries when running on Android in Release mode ([#4294](https://github.com/getsentry/sentry-dotnet/pull/4294))
- Fixed an issue with the way Sentry detects build settings. This was causing Sentry to produce code that could fail at runtime in AOT compiled applications. ([#4333](https://github.com/getsentry/sentry-dotnet/pull/4333))
- Native AOT: link to static `lzma` on Linux/MUSL ([#4326](https://github.com/getsentry/sentry-dotnet/pull/4326))
- AppDomain.CurrentDomain.ProcessExit hook is now removed on shutdown ([#4323](https://github.com/getsentry/sentry-dotnet/pull/4323))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,19 @@ public static bool TryReadStore(string inputFile, IList<string> supportedAbis, D
return assembly;
}

// If the assembly name ends with .dll or .exe, try to find it without the extension.
if ((IsFileType(".dll") || IsFileType(".exe")) && FindBestAssembly(name[..^4], out assembly))
{
return assembly;
}

// Conversely, if there is no extension, try with the dll extension (sometimes required for class libraries).
// See: https://github.com/getsentry/sentry-dotnet/issues/4278#issuecomment-2986009125
if (!IsFileType(".dll") && !IsFileType(".exe") && FindBestAssembly(name + ".dll", out assembly))
{
return assembly;
}

return null;

bool IsFileType(string extension)
Expand All @@ -119,10 +127,12 @@ private bool FindBestAssembly(string name, out ExplorerStoreItem? explorerAssemb
{
if (explorer.AssembliesByName?.TryGetValue(name, out var assembly) is true)
{
_logger?.Invoke("Found best assembly {0} in APK AssemblyStore for target arch {1}", name, explorer.TargetArch);
explorerAssembly = new(explorer, assembly);
return true;
}
}
_logger?.Invoke("No best assembly for {0} in APK AssemblyStore", name);
Copy link
Member

Choose a reason for hiding this comment

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

looks like we have one logger but shouldn't this be a level Error log?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'd have to refactor the AssemblyReader classes that we vendored in fomr MS in order to be able to do that (they use a different pattern for logging).

Probably the easiest would be to replace DebugLogger with our own IDiagnosticLogger... would involve quite a few changes, but then we've made so many changes to these already that the only way to merge in changes from new code is by hand. So a few more changes wouldn't hurt.

explorerAssembly = null;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private AssemblyStoreExplorer(Stream storeStream, string path, DebugLogger? logg
{
foreach (var item in Assemblies)
{
logger?.Invoke("Assembly {0} indexed from AssemblyStore {1}", item.Name, path);
dict.Add(item.Name, item);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<ProjectReference Include="..\Sentry.Extensions.Logging.Tests\Sentry.Extensions.Logging.Tests.csproj"/>
<ProjectReference Include="..\Sentry.Maui.Tests\Sentry.Maui.Tests.csproj"/>
<ProjectReference Include="..\Sentry.Maui.CommunityToolkit.Mvvm.Tests\Sentry.Maui.CommunityToolkit.Mvvm.Tests.csproj" Condition="'$(_SentryIsNet9OrGreater)' == 'true'"/>
<ProjectReference Include="..\..\src\Sentry.SourceGenerators\Sentry.SourceGenerators.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
</ItemGroup>

</Project>
Loading
Loading