Skip to content

Commit 281012b

Browse files
warning and error codes
1 parent 9377d62 commit 281012b

File tree

5 files changed

+50
-13
lines changed

5 files changed

+50
-13
lines changed

Documentation/guides/messages/xa4304.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Compiler Error XA4304
1+
# Compiler Warning XA4304
22

33
The `Proguard` MSBuild task encountered a proguard configuration file
44
that was not found on disk. These files are generally declared in your
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Compiler Error/Warning XA4305
2+
3+
The `CreateMultiDexMainDexClassList`, `CompileToDalvik` or `R8`
4+
MSBuild task encountered a `multidex.keep` file that was not found on
5+
disk. You can customize `multidex` settings for your Xamarin.Android
6+
application by adding files with the `MultiDexMainDexList` build item,
7+
which are combined into a final `multidex.keep` file.
8+
9+
To learn more about `multidex` and how it relates to Android
10+
development, see the [Android documentation][android].
11+
12+
## Resolution
13+
14+
Verify you are not declaring a `MultiDexMainDexList` build item that
15+
does not exist.
16+
17+
Consider submitting a [bug][bug] if you are getting this error/warning
18+
under normal circumstances.
19+
20+
[android]: https://developer.android.com/studio/build/multidex
21+
[bug]: https://github.com/xamarin/xamarin-android/wiki/Submitting-Bugs,-Feature-Requests,-and-Pull-Requests

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,14 @@ protected override string GenerateCommandLineCommands ()
116116
cmd.AppendSwitchIfNotNull ("--input-list=", inputListFile);
117117

118118
if (MultiDexEnabled) {
119-
cmd.AppendSwitch ("--multi-dex");
120-
cmd.AppendSwitchIfNotNull ("--main-dex-list=", MultiDexMainDexListFile);
119+
if (string.IsNullOrEmpty (MultiDexMainDexListFile)) {
120+
Log.LogCodedWarning ("XA4305", $"MultiDex is enabled, but '{nameof (MultiDexMainDexListFile)}' was not specified.");
121+
} else if (!File.Exists (MultiDexMainDexListFile)) {
122+
Log.LogCodedWarning ("XA4305", MultiDexMainDexListFile, 0, $"MultiDex is enabled, but main dex list file '{MultiDexMainDexListFile}' does not exist.");
123+
} else {
124+
cmd.AppendSwitch ("--multi-dex");
125+
cmd.AppendSwitchIfNotNull ("--main-dex-list=", MultiDexMainDexListFile);
126+
}
121127
}
122128
cmd.AppendSwitchIfNotNull ("--output ", Path.GetDirectoryName (ClassesOutputDirectory));
123129

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,16 @@ public override bool Execute ()
4747
Log.LogDebugMessage (" ProguardJarPath: {0}", ProguardJarPath);
4848
Log.LogDebugMessage (" ProguardInputJarFilter: {0}", ProguardInputJarFilter);
4949

50-
if (CustomMainDexListFiles != null && CustomMainDexListFiles.Any ()) {
51-
var content = string.Concat (CustomMainDexListFiles.Select (i => File.ReadAllText (i.ItemSpec)));
52-
File.WriteAllText (MultiDexMainDexListFile, content);
50+
if (CustomMainDexListFiles?.Length > 0) {
51+
var content = new List<string> ();
52+
foreach (var file in CustomMainDexListFiles) {
53+
if (File.Exists (file.ItemSpec)) {
54+
content.Add (File.ReadAllText (file.ItemSpec));
55+
} else {
56+
Log.LogCodedError ("XA4305", file.ItemSpec, 0, $"'MultiDexMainDexList' file '{file.ItemSpec}' does not exist.");
57+
}
58+
}
59+
File.WriteAllText (MultiDexMainDexListFile, string.Concat (content));
5360
return true;
5461
}
5562

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,19 @@ protected override string GenerateCommandLineCommands ()
9595
if (File.Exists (file))
9696
cmd.AppendSwitchIfNotNull ("--pg-conf ", file);
9797
else
98-
Log.LogWarning ("Proguard configuration file '{0}' was not found.", file);
98+
Log.LogCodedWarning ("XA4304", file, 0, "Proguard configuration file '{0}' was not found.", file);
9999
}
100100
cmd.AppendSwitchIfNotNull ("--pg-map-output ", ProguardMappingOutput);
101+
}
101102

102-
// multidexing
103-
if (EnableMultiDex) {
104-
if (!string.IsNullOrWhiteSpace (MultiDexMainDexListFile) && File.Exists (MultiDexMainDexListFile))
105-
cmd.AppendSwitchIfNotNull ("--main-dex-list ", MultiDexMainDexListFile);
106-
else
107-
Log.LogWarning ($"MultiDex is enabled, but main dex list file '{MultiDexMainDexListFile}' does not exist.");
103+
// multidexing
104+
if (EnableMultiDex) {
105+
if (string.IsNullOrEmpty (MultiDexMainDexListFile)) {
106+
Log.LogCodedWarning ("XA4305", $"MultiDex is enabled, but '{nameof (MultiDexMainDexListFile)}' was not specified.");
107+
} else if (!File.Exists (MultiDexMainDexListFile)) {
108+
Log.LogCodedWarning ("XA4305", MultiDexMainDexListFile, 0, $"MultiDex is enabled, but main dex list file '{MultiDexMainDexListFile}' does not exist.");
109+
} else {
110+
cmd.AppendSwitchIfNotNull ("--main-dex-list ", MultiDexMainDexListFile);
108111
}
109112
}
110113

0 commit comments

Comments
 (0)