From c61f61e2fca84a67cc8ae9fd9d36ab9785db4261 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Tue, 31 Jan 2023 18:20:15 -0800 Subject: [PATCH] Update Sentry.NET SDK to 3.27.0 and support symbolication on Android (#135) --- CHANGELOG.md | 24 +++++--- Directory.Build.props | 1 - README.md | 5 -- .../Sentry.Xamarin.Forms.csproj | 1 - .../Internals/SentryAndroidHelpers.droid.cs | 57 +++++++++++++++++++ Src/Sentry.Xamarin/Sentry.Xamarin.csproj | 2 + Src/Sentry.Xamarin/SentryXamarinOptions.cs | 11 ++++ 7 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 Src/Sentry.Xamarin/Internals/SentryAndroidHelpers.droid.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 735437f..b15b119 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,20 @@ # Changelog +## 1.5.0 + +### Features + + - Update Sentry.NET SDK to 3.27.0, which supports line numbers for Android ([#135](https://github.com/getsentry/sentry-xamarin/pull/135)) + - [changelog](https://github.com/getsentry/sentry-dotnet/blob/3.27.0/CHANGELOG.md) + - [diff](https://github.com/getsentry/sentry-dotnet/compare/3.26.2...3.27.0) + ## 1.4.6 ### Fixes - Update Sentry.NET SDK to 3.26.2 ([#133](https://github.com/getsentry/sentry-xamarin/pull/133)) - - [changelog](https://github.com/getsentry/sentry-dotnet/blob/3.26.2/CHANGELOG.md) - - [diff](https://github.com/getsentry/sentry-dotnet/compare/3.23.1...3.26.2) + - [changelog](https://github.com/getsentry/sentry-dotnet/blob/3.26.2/CHANGELOG.md) + - [diff](https://github.com/getsentry/sentry-dotnet/compare/3.23.1...3.26.2) ## 1.4.5 @@ -19,24 +27,24 @@ ### Fixes - Update Sentry.NET SDK to 3.23.1 ([#128](https://github.com/getsentry/sentry-xamarin/pull/128)) - - [changelog](https://github.com/getsentry/sentry-dotnet/blob/3.23.1/CHANGELOG.md) - - [diff](https://github.com/getsentry/sentry-dotnet/compare/3.22.0...3.23.1) + - [changelog](https://github.com/getsentry/sentry-dotnet/blob/3.23.1/CHANGELOG.md) + - [diff](https://github.com/getsentry/sentry-dotnet/compare/3.22.0...3.23.1) ## 1.4.3 ### Fixes - Update Sentry.NET SDK to 3.22.0 ([#127](https://github.com/getsentry/sentry-xamarin/pull/127)) - - [changelog](https://github.com/getsentry/sentry-dotnet/blob/3.22.0/CHANGELOG.md) - - [diff](https://github.com/getsentry/sentry-dotnet/compare/3.20.1...3.22.0) + - [changelog](https://github.com/getsentry/sentry-dotnet/blob/3.22.0/CHANGELOG.md) + - [diff](https://github.com/getsentry/sentry-dotnet/compare/3.20.1...3.22.0) ## 1.4.2 ### Fixes - Update Sentry.NET SDK to 3.20.1 ([#125](https://github.com/getsentry/sentry-xamarin/pull/125)) - - [changelog](https://github.com/getsentry/sentry-dotnet/blob/3.20.1/CHANGELOG.md) - - [diff](https://github.com/getsentry/sentry-dotnet/compare/3.17.1...3.20.1) + - [changelog](https://github.com/getsentry/sentry-dotnet/blob/3.20.1/CHANGELOG.md) + - [diff](https://github.com/getsentry/sentry-dotnet/compare/3.17.1...3.20.1) ## 1.4.1 diff --git a/Directory.Build.props b/Directory.Build.props index 5a8a570..28b40a6 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -9,7 +9,6 @@ - diff --git a/README.md b/README.md index 9fa439a..9d8d2d7 100644 --- a/README.md +++ b/README.md @@ -107,11 +107,6 @@ The package requires the following versions or newer: * Xamarin.Essentials 1.4.0 * Sentry 3.0.0 - -## Limitations - -There are no line numbers on stack traces for UWP and in release builds for Android and iOS, furthermore, mono symbolication is not yet supported. - ## Resources * [![Documentation](https://img.shields.io/badge/documentation-sentry.io-green.svg)](https://docs.sentry.io/platforms/dotnet/) diff --git a/Src/Sentry.Xamarin.Forms/Sentry.Xamarin.Forms.csproj b/Src/Sentry.Xamarin.Forms/Sentry.Xamarin.Forms.csproj index 101e298..9ff18f6 100644 --- a/Src/Sentry.Xamarin.Forms/Sentry.Xamarin.Forms.csproj +++ b/Src/Sentry.Xamarin.Forms/Sentry.Xamarin.Forms.csproj @@ -21,7 +21,6 @@ - diff --git a/Src/Sentry.Xamarin/Internals/SentryAndroidHelpers.droid.cs b/Src/Sentry.Xamarin/Internals/SentryAndroidHelpers.droid.cs new file mode 100644 index 0000000..81996ed --- /dev/null +++ b/Src/Sentry.Xamarin/Internals/SentryAndroidHelpers.droid.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Sentry.Android.AssemblyReader; +using Sentry.Extensibility; + +using Appliction = Android.App.Application; +using AndroidBuild = Android.OS.Build; + +namespace Sentry.Xamarin.Internals +{ + internal static class SentryAndroidHelpers + { + public static IList GetSupportedAbis() + { + var result = AndroidBuild.SupportedAbis; + if (result != null) + { + return result; + } + +#pragma warning disable CS0618 + var abi = AndroidBuild.CpuAbi; +#pragma warning restore CS0618 + + return abi != null ? new[] {abi} : Array.Empty(); + } + + public static IAndroidAssemblyReader? GetAndroidAssemblyReader(IDiagnosticLogger? logger) + { + var apkPath = Appliction.Context.ApplicationInfo?.SourceDir; + if (apkPath == null) + { + logger?.LogWarning("Can't determine APK path."); + return null; + } + + if (!File.Exists(apkPath)) + { + logger?.LogWarning("APK doesn't exist at {0}", apkPath); + return null; + } + + try + { + var supportedAbis = GetSupportedAbis(); + return AndroidAssemblyReaderFactory.Open(apkPath, supportedAbis, + logger: (message, args) => logger?.Log(SentryLevel.Debug, message, args: args)); + } + catch (Exception ex) + { + logger?.LogError("Cannot create assembly reader.", ex); + return null; + } + } + } +} \ No newline at end of file diff --git a/Src/Sentry.Xamarin/Sentry.Xamarin.csproj b/Src/Sentry.Xamarin/Sentry.Xamarin.csproj index bddf03f..ad06656 100644 --- a/Src/Sentry.Xamarin/Sentry.Xamarin.csproj +++ b/Src/Sentry.Xamarin/Sentry.Xamarin.csproj @@ -42,6 +42,8 @@ + + diff --git a/Src/Sentry.Xamarin/SentryXamarinOptions.cs b/Src/Sentry.Xamarin/SentryXamarinOptions.cs index 2e00eca..122ac83 100644 --- a/Src/Sentry.Xamarin/SentryXamarinOptions.cs +++ b/Src/Sentry.Xamarin/SentryXamarinOptions.cs @@ -1,6 +1,11 @@ using Sentry.Internals.Session; using Sentry.Xamarin.Internals; +#if __ANDROID__ +using System; +using Sentry.Android.AssemblyReader; +#endif + namespace Sentry { /// @@ -46,6 +51,12 @@ public SentryXamarinOptions() IsEnvironmentUser = false; AutoSessionTracking = true; IsGlobalModeEnabled = true; + +#if __ANDROID__ + var reader = new Lazy(() => + SentryAndroidHelpers.GetAndroidAssemblyReader(DiagnosticLogger)); + AssemblyReader = name => reader.Value?.TryReadAssembly(name); +#endif } } }