Skip to content
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

fix: Updated Android debug symbol upload #1995

Merged
merged 8 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Fixes

- The SDK's build logs when targeting Android are not a lot less noisy. The SDK will also no longer omit the sentry-cli logs from the gradle build output. ([#1995](https://github.com/getsentry/sentry-unity/pull/1995))
- When targeting iOS and disabling native support, the SDK no longer causes builds to fail with an `Undefined symbol: _SentryNativeBridgeIsEnabled` error. ([#1983](https://github.com/getsentry/sentry-unity/pull/1983))

### Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public void OnPostGenerateGradleAndroidProject(string basePath)

CopyAndroidSdkToGradleProject(unityProjectPath, gradleProjectPath);
AddAndroidSdkDependencies(gradleProjectPath);

if (_sentryCliOptions?.IgnoreCliErrors is true)
{
_logger.LogWarning("Sentry CLI errors will be ignored during build. BE AWARE you might have " +
"unminified/unsymbolicated crashes in production if the debug symbol upload fails. " +
"When using this flag, you should download your sourcemaps/debug files, to re-run the " +
"upload symbols command at a later point.");
}

SetupSymbolsUpload(unityProjectPath, gradleProjectPath);
SetupProguard(gradleProjectPath);
}
Expand Down
85 changes: 36 additions & 49 deletions src/Sentry.Unity.Editor/Android/DebugSymbolUpload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ internal class DebugSymbolUpload
private readonly string _gradleScriptPath;
private readonly bool _isExporting;
private readonly bool _isMinifyEnabled;
private readonly bool _ignoreCliErrors;

private readonly SentryCliOptions? _cliOptions;
private readonly List<string> _symbolUploadPaths;
Expand All @@ -35,7 +34,7 @@ internal class DebugSymbolUpload
private const string SymbolUploadTaskEndComment = "// Autogenerated Sentry symbol upload task [end]";
private const string SentryCliMarker = "SENTRY_CLI";
private const string UploadArgsMarker = "UPLOAD_ARGS";
private const string MappingPathMarker = "MAPPING_PATH";
private const string ProguardArgsMarker = "PROGUARD_ARGS";

private string SymbolUploadTaskFormat
{
Expand All @@ -46,41 +45,26 @@ private string SymbolUploadTaskFormat
stringBuilder.AppendLine("afterEvaluate {");
stringBuilder.AppendLine("task sentryUploadSymbols {");
stringBuilder.AppendLine(" doLast {");
if (_isExporting)
{
stringBuilder.AppendLine(" println 'Uploading symbols to Sentry.'");
}
else
{
var logsDir = $"{ConvertSlashes(_unityProjectPath)}/Logs";
Directory.CreateDirectory(logsDir);
stringBuilder.AppendLine(" println 'Uploading symbols to Sentry. You can find the full log in ./Logs/sentry-symbols-upload.log (the file content may not be strictly sequential because it\\'s a merge of two streams).'");
stringBuilder.AppendLine($" def logFilePath = '{logsDir}/{SymbolUploadLogName}'");
stringBuilder.AppendLine(" def sentryLogFile = new FileOutputStream(logFilePath)");
if (_ignoreCliErrors)
{
stringBuilder.AppendLine(" try {");
}
}
stringBuilder.AppendLine(" println 'Uploading symbols to Sentry.'");

var logsDir = $"{ConvertSlashes(_unityProjectPath)}/Logs";
Directory.CreateDirectory(logsDir);
stringBuilder.AppendLine($" def logFilePath = '{logsDir}/{SymbolUploadLogName}'");
stringBuilder.AppendLine(" def sentryLogFile = new FileOutputStream(logFilePath)");
stringBuilder.AppendLine(" def outputStream = new org.apache.tools.ant.util.TeeOutputStream(System.out, sentryLogFile)");
stringBuilder.AppendLine(" def errorStream = new org.apache.tools.ant.util.TeeOutputStream(System.err, sentryLogFile)");

stringBuilder.AppendLine(" exec {");
stringBuilder.AppendLine(" environment 'SENTRY_PROPERTIES', './sentry.properties'");
stringBuilder.AppendLine($" executable '{SentryCliMarker}'");
stringBuilder.AppendLine($" args = ['debug-files', 'upload'{UploadArgsMarker}]");
if (!_isExporting)
{
stringBuilder.AppendLine(" standardOutput sentryLogFile");
stringBuilder.AppendLine(" errorOutput sentryLogFile");
stringBuilder.AppendLine(" standardOutput outputStream");
stringBuilder.AppendLine(" errorOutput errorStream");
}

stringBuilder.AppendLine(" }");
if (!_isExporting && _ignoreCliErrors)
{
stringBuilder.AppendLine(" } catch (exception) {");
stringBuilder.AppendLine(" def file = new File(logFilePath)");
stringBuilder.AppendLine(" file.append('===ERROR===' + exception)");
stringBuilder.AppendLine(" }");
}

CheckMapping(stringBuilder);
stringBuilder.AppendLine(" }");
stringBuilder.AppendLine("}");
Expand Down Expand Up @@ -110,7 +94,6 @@ public DebugSymbolUpload(IDiagnosticLogger logger,
_gradleScriptPath = Path.Combine(_gradleProjectPath, "launcher/build.gradle");
_isExporting = isExporting;
_isMinifyEnabled = minifyEnabled;
_ignoreCliErrors = cliOptions != null && cliOptions.IgnoreCliErrors;

_cliOptions = cliOptions;
_symbolUploadPaths = GetSymbolUploadPaths(application);
Expand All @@ -130,23 +113,29 @@ public void AppendUploadToGradleFile(string sentryCliPath)
}

var uploadDifArguments = ", '--il2cpp-mapping'";
if (_cliOptions != null && _cliOptions.UploadSources)
if (_cliOptions?.UploadSources == true)
{
uploadDifArguments += ", '--include-sources'";
}

if (_cliOptions?.IgnoreCliErrors == true)
{
uploadDifArguments += ", '--allow-failure'";
}

if (_isExporting)
{
_logger.LogInfo("Project is exporting. Setting upload-dif to 'project.rootDir'");

uploadDifArguments += ", project.rootDir";
sentryCliPath = $"./{Path.GetFileName(sentryCliPath)}";
}
else
else if (_symbolUploadPaths.Count > 0)
{
_logger.LogInfo("Setting upload-dif paths");

foreach (var symbolUploadPath in _symbolUploadPaths)
{
_logger.LogInfo("Setting upload-dif paths");
if (Directory.Exists(symbolUploadPath))
{
_logger.LogDebug("Adding '{0}'", symbolUploadPath);
Expand All @@ -159,11 +148,19 @@ public void AppendUploadToGradleFile(string sentryCliPath)
}
}

var uploadProguardArguments = string.Empty;
if (_cliOptions?.IgnoreCliErrors == true)
{
uploadProguardArguments += ", '--allow-failure'";
}

uploadProguardArguments += $", '{_mappingFilePath}'";

var symbolUploadText = SymbolUploadTaskFormat;
symbolUploadText = symbolUploadText.Trim();
symbolUploadText = symbolUploadText.Replace(SentryCliMarker, sentryCliPath);
symbolUploadText = symbolUploadText.Replace(UploadArgsMarker, uploadDifArguments);
symbolUploadText = symbolUploadText.Replace(MappingPathMarker, _mappingFilePath);
symbolUploadText = symbolUploadText.Replace(ProguardArgsMarker, uploadProguardArguments);

using var streamWriter = File.AppendText(_gradleScriptPath);
streamWriter.WriteLine(SymbolUploadTaskStartComment);
Expand Down Expand Up @@ -263,29 +260,20 @@ private void CheckMapping(StringBuilder stringBuilder)
Directory.CreateDirectory(logsDir);
stringBuilder.AppendLine($" def mappingLogFilePath = '{logsDir}/{MappingUploadLogName}'");
stringBuilder.AppendLine($" def mappingLogFile = new FileOutputStream(mappingLogFilePath)");
if (!_isExporting && _ignoreCliErrors)
{
stringBuilder.AppendLine(" try {");
}
stringBuilder.AppendLine(" def mappingOutputStream = new org.apache.tools.ant.util.TeeOutputStream(System.out, mappingLogFile)");
stringBuilder.AppendLine(" def mappingErrorStream = new org.apache.tools.ant.util.TeeOutputStream(System.err, mappingLogFile)");
}
stringBuilder.AppendLine(" exec {");
stringBuilder.AppendLine(" environment 'SENTRY_PROPERTIES', './sentry.properties'");
stringBuilder.AppendLine($" executable '{SentryCliMarker}'");
stringBuilder.AppendLine($" args = ['upload-proguard', {MappingPathMarker}]");
stringBuilder.AppendLine($" args = ['upload-proguard'{ProguardArgsMarker}]");
// stringBuilder.AppendLine($" args = ['debug-files', 'upload'{UploadArgsMarker}]");
if (!_isExporting)
{
stringBuilder.AppendLine(" standardOutput mappingLogFile");
stringBuilder.AppendLine(" errorOutput mappingLogFile");
stringBuilder.AppendLine(" standardOutput mappingOutputStream");
stringBuilder.AppendLine(" errorOutput mappingErrorStream");
}

stringBuilder.AppendLine(" }");
if (!_isExporting && _ignoreCliErrors)
{
stringBuilder.AppendLine(" } catch (exception) {");
stringBuilder.AppendLine(" def file = new File(mappingLogFilePath)");
stringBuilder.AppendLine(" file.append('===ERROR===' + exception)");
stringBuilder.AppendLine(" }");
}
}

private string GetMappingFilePath(IApplication? application)
Expand All @@ -305,7 +293,6 @@ private string GetMappingFilePath(IApplication? application)
{
var gradleProjectPath = Path.Combine(_unityProjectPath, gradleRelativePath);
mappingPathFormat = Path.Combine(gradleProjectPath, "launcher/build/outputs/mapping/{0}/mapping.txt");
mappingPathFormat = $"'{mappingPathFormat}'";
}

var mappingPath = mappingPathFormat.Replace("{0}", buildType);
Expand Down
155 changes: 0 additions & 155 deletions src/Sentry.Unity.Editor/Android/PostBuildCheck.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,20 @@ public void AppendUploadToGradleFile_AllRequirementsMet_AppendsUploadTask(bool i

if (!isExporting)
{
keywords.Add("logFilePath");
keywords.Add("standardOutput outputStream");
}

if (!isExporting && ignoreCliErrors)
if (ignoreCliErrors)
{
keywords.Add("try {");
keywords.Add("} catch");
keywords.Add("--allow-failure");
}

if (addMapping)
{
keywords.Add("args = ['upload-proguard'");
if (!isExporting)
{
keywords.Add("mappingLogFile");
keywords.Add("standardOutput mappingOutputStream");
}
}

Expand Down
Loading