Skip to content

Commit 4c80910

Browse files
jonathanpeppersjonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] r8 duplicate resource warnings -> messages (#4001)
Fixes: #3622 Context: https://r8.googlesource.com/r8/ Just building a Xamairn.Forms template with multi-dex enabled produces the warning: R8 : warning : Resource 'META-INF/MANIFEST.MF' already exists. There are also other reports of: R8 : warning : Resource 'META-INF/MSFTSIG.SF' already exists. R8 : warning : Resource 'META-INF/MSFTSIG.RSA' already exists. Reviewing r8's source code, I see no way to prevent it from emitting these messages. For now, it seems simple enough to add a `Regex` for this message and downgrade it to a regular MSBuild message. I added a test for this scenario as well, however I was also getting this message from r8: Warning: The rule `-keep public class * extends java.lang.annotation.Annotation { *; }` uses extends but actually matches implements. I don't think we should downgrade this one, yet... I reworked the test so allow 1 warning and used a property to disable a warning coming from Xamarin.Build.Download.
1 parent a963b97 commit 4c80910

File tree

2 files changed

+36
-5
lines changed
  • src/Xamarin.Android.Build.Tasks

2 files changed

+36
-5
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.Build.Utilities;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Text.RegularExpressions;
56
using Xamarin.Android.Tools;
67

78
namespace Xamarin.Android.Tasks
@@ -110,5 +111,20 @@ protected virtual CommandLineBuilder GetCommandLineBuilder ()
110111

111112
return cmd;
112113
}
114+
115+
/// <summary>
116+
/// r8 tends to print:
117+
/// Warning: Resource 'META-INF/MANIFEST.MF' already exists.
118+
/// </summary>
119+
static readonly Regex resourceWarning = new Regex ("Warning: Resource.+already exists", RegexOptions.IgnoreCase | RegexOptions.Compiled);
120+
121+
protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
122+
{
123+
if (resourceWarning.IsMatch (singleLine)) {
124+
Log.LogMessage (messageImportance, singleLine);
125+
} else {
126+
base.LogEventsFromTextOutput (singleLine, messageImportance);
127+
}
128+
}
113129
}
114-
}
130+
}

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,55 +70,70 @@ public void BuildBasicApplicationReleaseProfiledAotWithoutDefaultProfile ()
7070
new object [] {
7171
/* isRelease */ false,
7272
/* xamarinForms */ false,
73+
/* multidex */ false,
7374
/* packageFormat */ "apk",
7475
},
7576
new object [] {
7677
/* isRelease */ false,
7778
/* xamarinForms */ true,
79+
/* multidex */ false,
80+
/* packageFormat */ "apk",
81+
},
82+
new object [] {
83+
/* isRelease */ false,
84+
/* xamarinForms */ true,
85+
/* multidex */ true,
7886
/* packageFormat */ "apk",
7987
},
8088
new object [] {
8189
/* isRelease */ true,
8290
/* xamarinForms */ false,
91+
/* multidex */ false,
8392
/* packageFormat */ "apk",
8493
},
8594
new object [] {
8695
/* isRelease */ true,
8796
/* xamarinForms */ true,
97+
/* multidex */ false,
8898
/* packageFormat */ "apk",
8999
},
90100
new object [] {
91101
/* isRelease */ false,
92102
/* xamarinForms */ false,
103+
/* multidex */ false,
93104
/* packageFormat */ "aab",
94105
},
95106
new object [] {
96107
/* isRelease */ true,
97108
/* xamarinForms */ false,
109+
/* multidex */ false,
98110
/* packageFormat */ "aab",
99111
},
100112
};
101113

102114
[Test]
103115
[TestCaseSource (nameof (BuildHasNoWarningsSource))]
104-
public void BuildHasNoWarnings (bool isRelease, bool xamarinForms, string packageFormat)
116+
public void BuildHasNoWarnings (bool isRelease, bool xamarinForms, bool multidex, string packageFormat)
105117
{
106118
var proj = xamarinForms ?
107119
new XamarinFormsAndroidApplicationProject () :
108120
new XamarinAndroidApplicationProject ();
121+
if (multidex) {
122+
proj.SetProperty ("AndroidEnableMultiDex", "True");
123+
}
109124
if (packageFormat == "aab") {
110125
// Disable fast deployment for aabs, because we give:
111126
// XA0119: Using Fast Deployment and Android App Bundles at the same time is not recommended.
112127
proj.EmbedAssembliesIntoApk = true;
113128
proj.AndroidUseSharedRuntime = false;
114129
}
130+
proj.SetProperty ("XamarinAndroidSupportSkipVerifyVersions", "True"); // Disables API 29 warning in Xamarin.Build.Download
115131
proj.SetProperty ("AndroidPackageFormat", packageFormat);
116132
proj.IsRelease = isRelease;
117133
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
118134
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
119-
if (xamarinForms) {
120-
// With Android API Level 29, we will get a warning: "... is only compatible with TargetFrameworkVersion: MonoAndroid,v9.0 (Android API Level 28)"
121-
// We should allow a maximum of 1 warning to cover this case until the packages get updated to be compatible with Api level 29
135+
if (multidex) {
136+
// R8 currently gives: The rule `-keep public class * extends java.lang.annotation.Annotation { *; }` uses extends but actually matches implements.
122137
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, " 1 Warning(s)"), "Should have no more than 1 MSBuild warnings.");
123138
} else {
124139
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, " 0 Warning(s)"), "Should have no MSBuild warnings.");

0 commit comments

Comments
 (0)