Skip to content

Commit 25a73d6

Browse files
authored
fix: Updated Android debug symbol upload (#1995)
1 parent a7646d6 commit 25a73d6

File tree

5 files changed

+50
-209
lines changed

5 files changed

+50
-209
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Fixes
1010

11+
- 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))
1112
- 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))
1213

1314
### Dependencies

src/Sentry.Unity.Editor/Android/AndroidManifestConfiguration.cs

+9
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ public void OnPostGenerateGradleAndroidProject(string basePath)
9696

9797
CopyAndroidSdkToGradleProject(unityProjectPath, gradleProjectPath);
9898
AddAndroidSdkDependencies(gradleProjectPath);
99+
100+
if (_sentryCliOptions?.IgnoreCliErrors is true)
101+
{
102+
_logger.LogWarning("Sentry CLI errors will be ignored during build. BE AWARE you might have " +
103+
"unminified/unsymbolicated crashes in production if the debug symbol upload fails. " +
104+
"When using this flag, you should store built sourcemaps and debug files, to re-run the " +
105+
"upload symbols command at a later point.");
106+
}
107+
99108
SetupSymbolsUpload(unityProjectPath, gradleProjectPath);
100109
SetupProguard(gradleProjectPath);
101110
}

src/Sentry.Unity.Editor/Android/DebugSymbolUpload.cs

+36-49
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ internal class DebugSymbolUpload
2525
private readonly string _gradleScriptPath;
2626
private readonly bool _isExporting;
2727
private readonly bool _isMinifyEnabled;
28-
private readonly bool _ignoreCliErrors;
2928

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

4039
private string SymbolUploadTaskFormat
4140
{
@@ -46,41 +45,26 @@ private string SymbolUploadTaskFormat
4645
stringBuilder.AppendLine("afterEvaluate {");
4746
stringBuilder.AppendLine("task sentryUploadSymbols {");
4847
stringBuilder.AppendLine(" doLast {");
49-
if (_isExporting)
50-
{
51-
stringBuilder.AppendLine(" println 'Uploading symbols to Sentry.'");
52-
}
53-
else
54-
{
55-
var logsDir = $"{ConvertSlashes(_unityProjectPath)}/Logs";
56-
Directory.CreateDirectory(logsDir);
57-
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).'");
58-
stringBuilder.AppendLine($" def logFilePath = '{logsDir}/{SymbolUploadLogName}'");
59-
stringBuilder.AppendLine(" def sentryLogFile = new FileOutputStream(logFilePath)");
60-
if (_ignoreCliErrors)
61-
{
62-
stringBuilder.AppendLine(" try {");
63-
}
64-
}
48+
stringBuilder.AppendLine(" println 'Uploading symbols to Sentry.'");
49+
50+
var logsDir = $"{ConvertSlashes(_unityProjectPath)}/Logs";
51+
Directory.CreateDirectory(logsDir);
52+
stringBuilder.AppendLine($" def logFilePath = '{logsDir}/{SymbolUploadLogName}'");
53+
stringBuilder.AppendLine(" def sentryLogFile = new FileOutputStream(logFilePath)");
54+
stringBuilder.AppendLine(" def outputStream = new org.apache.tools.ant.util.TeeOutputStream(System.out, sentryLogFile)");
55+
stringBuilder.AppendLine(" def errorStream = new org.apache.tools.ant.util.TeeOutputStream(System.err, sentryLogFile)");
6556

6657
stringBuilder.AppendLine(" exec {");
6758
stringBuilder.AppendLine(" environment 'SENTRY_PROPERTIES', './sentry.properties'");
6859
stringBuilder.AppendLine($" executable '{SentryCliMarker}'");
6960
stringBuilder.AppendLine($" args = ['debug-files', 'upload'{UploadArgsMarker}]");
7061
if (!_isExporting)
7162
{
72-
stringBuilder.AppendLine(" standardOutput sentryLogFile");
73-
stringBuilder.AppendLine(" errorOutput sentryLogFile");
63+
stringBuilder.AppendLine(" standardOutput outputStream");
64+
stringBuilder.AppendLine(" errorOutput errorStream");
7465
}
75-
7666
stringBuilder.AppendLine(" }");
77-
if (!_isExporting && _ignoreCliErrors)
78-
{
79-
stringBuilder.AppendLine(" } catch (exception) {");
80-
stringBuilder.AppendLine(" def file = new File(logFilePath)");
81-
stringBuilder.AppendLine(" file.append('===ERROR===' + exception)");
82-
stringBuilder.AppendLine(" }");
83-
}
67+
8468
CheckMapping(stringBuilder);
8569
stringBuilder.AppendLine(" }");
8670
stringBuilder.AppendLine("}");
@@ -110,7 +94,6 @@ public DebugSymbolUpload(IDiagnosticLogger logger,
11094
_gradleScriptPath = Path.Combine(_gradleProjectPath, "launcher/build.gradle");
11195
_isExporting = isExporting;
11296
_isMinifyEnabled = minifyEnabled;
113-
_ignoreCliErrors = cliOptions != null && cliOptions.IgnoreCliErrors;
11497

11598
_cliOptions = cliOptions;
11699
_symbolUploadPaths = GetSymbolUploadPaths(application);
@@ -130,23 +113,29 @@ public void AppendUploadToGradleFile(string sentryCliPath)
130113
}
131114

132115
var uploadDifArguments = ", '--il2cpp-mapping'";
133-
if (_cliOptions != null && _cliOptions.UploadSources)
116+
if (_cliOptions?.UploadSources == true)
134117
{
135118
uploadDifArguments += ", '--include-sources'";
136119
}
137120

121+
if (_cliOptions?.IgnoreCliErrors == true)
122+
{
123+
uploadDifArguments += ", '--allow-failure'";
124+
}
125+
138126
if (_isExporting)
139127
{
140128
_logger.LogInfo("Project is exporting. Setting upload-dif to 'project.rootDir'");
141129

142130
uploadDifArguments += ", project.rootDir";
143131
sentryCliPath = $"./{Path.GetFileName(sentryCliPath)}";
144132
}
145-
else
133+
else if (_symbolUploadPaths.Count > 0)
146134
{
135+
_logger.LogInfo("Setting upload-dif paths");
136+
147137
foreach (var symbolUploadPath in _symbolUploadPaths)
148138
{
149-
_logger.LogInfo("Setting upload-dif paths");
150139
if (Directory.Exists(symbolUploadPath))
151140
{
152141
_logger.LogDebug("Adding '{0}'", symbolUploadPath);
@@ -159,11 +148,19 @@ public void AppendUploadToGradleFile(string sentryCliPath)
159148
}
160149
}
161150

151+
var uploadProguardArguments = string.Empty;
152+
if (_cliOptions?.IgnoreCliErrors == true)
153+
{
154+
uploadProguardArguments += ", '--allow-failure'";
155+
}
156+
157+
uploadProguardArguments += $", '{_mappingFilePath}'";
158+
162159
var symbolUploadText = SymbolUploadTaskFormat;
163160
symbolUploadText = symbolUploadText.Trim();
164161
symbolUploadText = symbolUploadText.Replace(SentryCliMarker, sentryCliPath);
165162
symbolUploadText = symbolUploadText.Replace(UploadArgsMarker, uploadDifArguments);
166-
symbolUploadText = symbolUploadText.Replace(MappingPathMarker, _mappingFilePath);
163+
symbolUploadText = symbolUploadText.Replace(ProguardArgsMarker, uploadProguardArguments);
167164

168165
using var streamWriter = File.AppendText(_gradleScriptPath);
169166
streamWriter.WriteLine(SymbolUploadTaskStartComment);
@@ -263,29 +260,20 @@ private void CheckMapping(StringBuilder stringBuilder)
263260
Directory.CreateDirectory(logsDir);
264261
stringBuilder.AppendLine($" def mappingLogFilePath = '{logsDir}/{MappingUploadLogName}'");
265262
stringBuilder.AppendLine($" def mappingLogFile = new FileOutputStream(mappingLogFilePath)");
266-
if (!_isExporting && _ignoreCliErrors)
267-
{
268-
stringBuilder.AppendLine(" try {");
269-
}
263+
stringBuilder.AppendLine(" def mappingOutputStream = new org.apache.tools.ant.util.TeeOutputStream(System.out, mappingLogFile)");
264+
stringBuilder.AppendLine(" def mappingErrorStream = new org.apache.tools.ant.util.TeeOutputStream(System.err, mappingLogFile)");
270265
}
271266
stringBuilder.AppendLine(" exec {");
272267
stringBuilder.AppendLine(" environment 'SENTRY_PROPERTIES', './sentry.properties'");
273268
stringBuilder.AppendLine($" executable '{SentryCliMarker}'");
274-
stringBuilder.AppendLine($" args = ['upload-proguard', {MappingPathMarker}]");
269+
stringBuilder.AppendLine($" args = ['upload-proguard'{ProguardArgsMarker}]");
270+
// stringBuilder.AppendLine($" args = ['debug-files', 'upload'{UploadArgsMarker}]");
275271
if (!_isExporting)
276272
{
277-
stringBuilder.AppendLine(" standardOutput mappingLogFile");
278-
stringBuilder.AppendLine(" errorOutput mappingLogFile");
273+
stringBuilder.AppendLine(" standardOutput mappingOutputStream");
274+
stringBuilder.AppendLine(" errorOutput mappingErrorStream");
279275
}
280-
281276
stringBuilder.AppendLine(" }");
282-
if (!_isExporting && _ignoreCliErrors)
283-
{
284-
stringBuilder.AppendLine(" } catch (exception) {");
285-
stringBuilder.AppendLine(" def file = new File(mappingLogFilePath)");
286-
stringBuilder.AppendLine(" file.append('===ERROR===' + exception)");
287-
stringBuilder.AppendLine(" }");
288-
}
289277
}
290278

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

311298
var mappingPath = mappingPathFormat.Replace("{0}", buildType);

src/Sentry.Unity.Editor/Android/PostBuildCheck.cs

-155
This file was deleted.

test/Sentry.Unity.Editor.Tests/Android/DebugSymbolUploadTests.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,20 @@ public void AppendUploadToGradleFile_AllRequirementsMet_AppendsUploadTask(bool i
155155

156156
if (!isExporting)
157157
{
158-
keywords.Add("logFilePath");
158+
keywords.Add("standardOutput outputStream");
159159
}
160160

161-
if (!isExporting && ignoreCliErrors)
161+
if (ignoreCliErrors)
162162
{
163-
keywords.Add("try {");
164-
keywords.Add("} catch");
163+
keywords.Add("--allow-failure");
165164
}
166165

167166
if (addMapping)
168167
{
169168
keywords.Add("args = ['upload-proguard'");
170169
if (!isExporting)
171170
{
172-
keywords.Add("mappingLogFile");
171+
keywords.Add("standardOutput mappingOutputStream");
173172
}
174173
}
175174

0 commit comments

Comments
 (0)