Skip to content

Commit 55a2366

Browse files
[Xamarin.Android.Build.Tasks] <Aapt /> task showing warnings as errors
Fixes: #1134 Context: 2135856 Dean's changes in 2135856 were more accurate at picking out warnings & errors, but if the `level` value from the `Regex` was blank, it was counting the message as an error. The `level` value is matching against the words `warning` or `error`, ignoring case. I think the fix here is to count the message as a warning if the `level` is blank. I added a Regex test case of what was on #1134. I added another test case that verifies a message with a blank `level` comes through the build output as a `warning`, not giving an `APT0000` error.
1 parent 59cfa5d commit 55a2366

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
371371
line = int.Parse (match.Groups["line"].Value) + 1;
372372
var level = match.Groups["level"].Value.ToLowerInvariant ();
373373
var message = match.Groups ["message"].Value;
374-
if (message.Contains ("fakeLogOpen") || level.Contains ("warning")) {
374+
if (message.Contains ("fakeLogOpen") || level.Contains ("warning") || string.IsNullOrEmpty (level)) {
375375
LogWarning (singleLine);
376376
return;
377377
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public IEnumerator GetEnumerator ()
7474
/*expectedLevel*/ "",
7575
/*expectedMessage*/ "max res 10, skipping values-sw600dp-land"
7676
};
77+
yield return new object [] {
78+
/*message*/ "max res 10, skipping values-sw720dp-land-v13",
79+
/*expectedToMatch*/ true,
80+
/*expectedFile*/ "",
81+
/*expectedLine*/ "",
82+
/*expectedLevel*/ "",
83+
/*expectedMessage*/ "max res 10, skipping values-sw720dp-land-v13"
84+
};
7785
yield return new object [] {
7886
/*message*/ "Error: unable to generate entry for resource data",
7987
/*expectedToMatch*/ true,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ public void ReportAaptErrorsInOriginalFileName ()
183183
}
184184
}
185185

186+
[Test]
187+
public void ReportAaptWarningsForBlankLevel ()
188+
{
189+
//This test should get the warning `Invalid file name: must contain only [a-z0-9_.]`
190+
// However, <Aapt /> still fails due to aapt failing, Resource.designer.cs is not generated
191+
var proj = new XamarinAndroidApplicationProject ();
192+
proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\drawable\\Image (1).png") { BinaryContent = () => XamarinAndroidCommonProject.icon_binary_mdpi });
193+
using (var b = CreateApkBuilder ("temp/ReportAaptWarningsForBlankLevel")) {
194+
b.ThrowOnBuildFailure = false;
195+
Assert.IsFalse (b.Build (proj), "Build should have failed.");
196+
StringAssertEx.DoesNotContain ("APT0000", b.LastBuildOutput, "An error message with a blank \"level\", should only report a warning!");
197+
Assert.IsTrue (b.Clean (proj), "Clean should have succeeded.");
198+
}
199+
}
200+
186201
[Test]
187202
public void RepetiviteBuildUpdateSingleResource ()
188203
{

0 commit comments

Comments
 (0)