Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] downgrade d8/r8 warning messages to info #7643

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Documentation/guides/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,14 @@ or use `-p:AndroidCreateProguardMappingFile=False` on the command line.

This property was added in Xamarin.Android 11.2.

## AndroidD8IgnoreWarnings

Specifies `--map-diagnostics warning info` to be passed to `d8`. The
default value is `True`, but can be set to `False` to enforce more
strict behavior. See the [D8 and R8 readme][r8-source] for details.

Added in .NET 8.

## AndroidR8IgnoreWarnings

Specifies
Expand All @@ -1118,8 +1126,13 @@ to continue with dex compilation even if certain warnings are
encountered. The default value is `True`, but can be set to `False` to
enforce more strict behavior. See the [ProGuard manual](https://www.guardsquare.com/manual/configuration/usage) for details.

Starting in .NET 8, specifies `--map-diagnostics warning info`. See
the [D8 and R8 readme][r8-source] for details.

Added in Xamarin.Android 10.3.

[r8-source]: https://r8.googlesource.com/r8/
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved

## AndroidR8JarPath

The path to `r8.jar` for use with the
Expand Down
29 changes: 13 additions & 16 deletions src/Xamarin.Android.Build.Tasks/Tasks/D8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.Build.Utilities;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Xamarin.Android.Tools;
using Microsoft.Android.Build.Tasks;

Expand Down Expand Up @@ -39,6 +38,7 @@ public class D8 : JavaToolTask
public ITaskItem [] JavaLibrariesToEmbed { get; set; }
public ITaskItem [] AlternativeJarLibrariesToEmbed { get; set; }
public ITaskItem [] JavaLibrariesToReference { get; set; }
public ITaskItem [] MapDiagnostics { get; set; }

public string ExtraArguments { get; set; }

Expand Down Expand Up @@ -110,22 +110,19 @@ protected virtual CommandLineBuilder GetCommandLineBuilder ()
foreach (var jar in injars)
cmd.AppendFileNameIfNotNull (jar);

return cmd;
}

/// <summary>
/// r8 tends to print:
/// Warning: Resource 'META-INF/MANIFEST.MF' already exists.
/// </summary>
static readonly Regex resourceWarning = new Regex ("Warning: Resource.+already exists", RegexOptions.IgnoreCase | RegexOptions.Compiled);

protected override void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
{
if (resourceWarning.IsMatch (singleLine)) {
Log.LogMessage (messageImportance, singleLine);
} else {
base.LogEventsFromTextOutput (singleLine, messageImportance);
if (MapDiagnostics != null) {
foreach (var diagnostic in MapDiagnostics) {
var from = diagnostic.ItemSpec;
var to = diagnostic.GetMetadata ("To");
if (string.IsNullOrEmpty (from) || string.IsNullOrEmpty (to))
continue;
cmd.AppendSwitch ("--map-diagnostics");
cmd.AppendSwitch (from);
cmd.AppendSwitch (to);
}
}

return cmd;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<AndroidEnableProguard Condition=" '$(AndroidLinkTool)' != '' ">True</AndroidEnableProguard>
<AndroidEnableDesugar Condition=" '$(AndroidEnableDesugar)' == '' And ('$(AndroidDexTool)' == 'd8' Or '$(AndroidLinkTool)' == 'r8') ">True</AndroidEnableDesugar>
<AndroidEnableDesugar Condition=" '$(AndroidEnableDesugar)' == '' ">False</AndroidEnableDesugar>
<AndroidD8IgnoreWarnings Condition=" '$(AndroidD8IgnoreWarnings)' == '' ">True</AndroidD8IgnoreWarnings>
<AndroidR8IgnoreWarnings Condition=" '$(AndroidR8IgnoreWarnings)' == '' ">True</AndroidR8IgnoreWarnings>
<AndroidCreateProguardMappingFile Condition="'$(AndroidCreateProguardMappingFile)' == '' And '$(AndroidLinkTool)' == 'r8'">True</AndroidCreateProguardMappingFile>

Expand Down
7 changes: 7 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.D8.targets
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Copyright (C) 2018 Xamarin. All rights reserved.
Condition=" '$(AndroidLinkTool)' != '' "
/>

<ItemGroup>
<_AndroidD8MapDiagnostics Condition=" '$(AndroidD8IgnoreWarnings)' == 'true' " Include="warning" To="info" />
<_AndroidR8MapDiagnostics Condition=" '$(AndroidR8IgnoreWarnings)' == 'true' " Include="warning" To="info" />
</ItemGroup>

<R8
Condition=" '$(_UseR8)' == 'True' "
ToolPath="$(JavaToolPath)"
Expand Down Expand Up @@ -77,6 +82,7 @@ Copyright (C) 2018 Xamarin. All rights reserved.
ExtraArguments="$(AndroidR8ExtraArguments)"
IntermediateOutputPath="$(IntermediateOutputPath)"
AssemblyIdentityMapFile="$(_AndroidLibrayProjectAssemblyMapFile)"
MapDiagnostics="@(_AndroidR8MapDiagnostics)"
/>
<D8
Condition=" '$(_UseR8)' != 'True' "
Expand All @@ -96,6 +102,7 @@ Copyright (C) 2018 Xamarin. All rights reserved.
ExtraArguments="$(AndroidD8ExtraArguments)"
IntermediateOutputPath="$(IntermediateOutputPath)"
AssemblyIdentityMapFile="$(_AndroidLibrayProjectAssemblyMapFile)"
MapDiagnostics="@(_AndroidD8MapDiagnostics)"
/>

<Touch Files="$(_AndroidStampDirectory)_CompileToDalvik.stamp" AlwaysCreate="true" />
Expand Down