Skip to content

Commit 92bc705

Browse files
[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 6e40a8f commit 92bc705

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
@@ -72,55 +72,70 @@ public void BuildBasicApplicationReleaseProfiledAotWithoutDefaultProfile ()
7272
new object [] {
7373
/* isRelease */ false,
7474
/* xamarinForms */ false,
75+
/* multidex */ false,
7576
/* packageFormat */ "apk",
7677
},
7778
new object [] {
7879
/* isRelease */ false,
7980
/* xamarinForms */ true,
81+
/* multidex */ false,
82+
/* packageFormat */ "apk",
83+
},
84+
new object [] {
85+
/* isRelease */ false,
86+
/* xamarinForms */ true,
87+
/* multidex */ true,
8088
/* packageFormat */ "apk",
8189
},
8290
new object [] {
8391
/* isRelease */ true,
8492
/* xamarinForms */ false,
93+
/* multidex */ false,
8594
/* packageFormat */ "apk",
8695
},
8796
new object [] {
8897
/* isRelease */ true,
8998
/* xamarinForms */ true,
99+
/* multidex */ false,
90100
/* packageFormat */ "apk",
91101
},
92102
new object [] {
93103
/* isRelease */ false,
94104
/* xamarinForms */ false,
105+
/* multidex */ false,
95106
/* packageFormat */ "aab",
96107
},
97108
new object [] {
98109
/* isRelease */ true,
99110
/* xamarinForms */ false,
111+
/* multidex */ false,
100112
/* packageFormat */ "aab",
101113
},
102114
};
103115

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

0 commit comments

Comments
 (0)