Skip to content

Commit 221a219

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] Fix Aapt2 warnings showing as errors (#2027)
Fixes (again): #1770 On Windows we are hitting the same issue where the warnings `aapt2` is producing are being logged as errors. The weird part is that the "file" group was not being populated with the right information. This turns out to be down to how `aapt2` is reporting the warnings: there may be *spaces* within the line number portion: W/ResourceType(23681): For resource 0x0101053d, entry index(1341) is beyond type entryCount(733) W/ResourceType( 5536): For resource 0x0101053d, entry index(1341) is beyond type entryCount(1155) ^ This space throws off our regex and results in the entire line ending up in the `message` property. The fix is to update the regex to allow spaces for the `line` capture group. We then also need to Trim that value before passing it into `int.Parse()` to ensure we don't get an error.
1 parent 967fe94 commit 221a219

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
412412
var file = match.Groups["file"].Value;
413413
int line = 0;
414414
if (!string.IsNullOrEmpty (match.Groups["line"]?.Value))
415-
line = int.Parse (match.Groups["line"].Value) + 1;
415+
line = int.Parse (match.Groups["line"].Value.Trim ()) + 1;
416416
var level = match.Groups["level"].Value.ToLowerInvariant ();
417417
var message = match.Groups ["message"].Value;
418418
if (message.Contains ("fakeLogOpen")) {

src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@ protected bool LogAapt2EventsFromOutput (string singleLine, MessageImportance me
103103
var file = match.Groups ["file"].Value;
104104
int line = 0;
105105
if (!string.IsNullOrEmpty (match.Groups ["line"]?.Value))
106-
line = int.Parse (match.Groups ["line"].Value) + 1;
106+
line = int.Parse (match.Groups ["line"].Value.Trim ()) + 1;
107107
var level = match.Groups ["level"].Value.ToLowerInvariant ();
108108
var message = match.Groups ["message"].Value;
109109

110110
// Handle the following which is NOT an error :(
111111
// W/ResourceType(23681): For resource 0x0101053d, entry index(1341) is beyond type entryCount(733)
112-
if (file.StartsWith ("W/")) {
112+
// W/ResourceType( 3681): For resource 0x0101053d, entry index(1341) is beyond type entryCount(733)
113+
if (file.StartsWith ("W/", StringComparison.OrdinalIgnoreCase)) {
113114
LogCodedWarning ("APT0000", singleLine);
114115
return true;
115116
}

src/Xamarin.Android.Build.Tasks/Tasks/AndroidToolTask.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public static Regex AndroidErrorRegex {
9191
(?<path>
9292
(?<file>.+[\\/][^:\(]+)
9393
(
94-
([:](?<line>\d+))
94+
([:](?<line>[\d ]+))
9595
|
96-
(\((?<line>\d+)\))
96+
(\((?<line>[\d ]+)\))
9797
)?
9898
)
9999
\s*

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidRegExTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ public IEnumerator GetEnumerator ()
130130
/*expectedLevel*/ "",
131131
/*expectedMessage*/ "invalid resource directory name: bar-55"
132132
};
133+
yield return new object [] {
134+
/*message*/ "W/ResourceType(23681): For resource 0x0101053d, entry index(1341) is beyond type entryCount(733)",
135+
/*expectedToMatch*/ true,
136+
/*expectedFile*/ "W/ResourceType",
137+
/*expectedLine*/ "23681",
138+
/*expectedLevel*/ "",
139+
/*expectedMessage*/ "For resource 0x0101053d, entry index(1341) is beyond type entryCount(733)"
140+
};
141+
yield return new object [] {
142+
/*message*/ "W/ResourceType( 5536): For resource 0x0101053d, entry index(1341) is beyond type entryCount(1155)",
143+
/*expectedToMatch*/ true,
144+
/*expectedFile*/ "W/ResourceType",
145+
/*expectedLine*/ " 5536",
146+
/*expectedLevel*/ "",
147+
/*expectedMessage*/ "For resource 0x0101053d, entry index(1341) is beyond type entryCount(1155)"
148+
};
133149
}
134150
}
135151

0 commit comments

Comments
 (0)