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

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Dec 15, 2022

Fixes: dotnet/maui#10901

Building a .NET MAUI project such as:

dotnet new maui
dotnet build -c Release -f net6.0-android -p:AndroidLinkMode=r8

Results in build warnings from R8 such as:

R8 : warning : Missing class androidx.window.extensions.WindowExtensions

In 92bc705, we already had attempted to silence warnings from R8 such as:

R8 : warning : Resource 'META-INF/MANIFEST.MF' already exists.

At the time, there was no option to hide warnings, now there is!

--map-diagnostics[:<type>] <from-level> <to-level>
    # Map diagnostics of <type> (default any) reported as
    # <from-level> to <to-level> where <from-level> and
    # <to-level> are one of 'info', 'warning', or 'error' and the
    # optional <type> is either the simple or fully qualified
    # Java type name of a diagnostic. If <type> is unspecified,
    # all diagnostics at <from-level> will be mapped.
    # Note that fatal compiler errors cannot be mapped.

We can pass:

--map-diagnostics warning info

Which can be done in existing apps via:

<AndroidD8ExtraArguments>--map-diagnostics warning info</AndroidD8ExtraArguments>
<AndroidR8ExtraArguments>--map-diagnostics warning info</AndroidR8ExtraArguments>

To solve this problem, let's create a new $(AndroidD8IgnoreWarnings) MSBuild property and make use of one we already have $(AndroidR8IgnoreWarnings):

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

We can then use these item groups to pass --map-diagnostics as appropriate. Developers can turn off either property to disable this behavior.

We can then remove the weird Regex code added in 92bc705. The existing tests from 92bc705 should also be sufficient for testing this change.

Now r8 emits:

Info: Missing class androidx.window.extensions.WindowExtensions (referenced from: androidx.window.extensions.layout.WindowLayoutComponent androidx.window.layout.SafeWindowLayoutComponentProvider$windowLayoutComponent$2.invoke())
Info: Resource 'META-INF/MANIFEST.MF' already exists.

And you don't get an MSBuild warning anymore.

Fixes: dotnet/maui#10901

Building a .NET MAUI project such as:

    dotnet new maui
    dotnet build -c Release -f net6.0-android -p:AndroidLinkMode=r8

Results in build warnings from R8 such as:

    R8 : warning : Missing class androidx.window.extensions.WindowExtensions

In 92bc705, we already had attempted to silence warnings from R8 such as:

    R8 : warning : Resource 'META-INF/MANIFEST.MF' already exists.

At the time, there was no option to hide warnings, now there is!

    --map-diagnostics[:<type>] <from-level> <to-level>
        # Map diagnostics of <type> (default any) reported as
        # <from-level> to <to-level> where <from-level> and
        # <to-level> are one of 'info', 'warning', or 'error' and the
        # optional <type> is either the simple or fully qualified
        # Java type name of a diagnostic. If <type> is unspecified,
        # all diagnostics at <from-level> will be mapped.
        # Note that fatal compiler errors cannot be mapped.

We can pass:

    --map-diagnostics warning info

Which can be done in existing apps via:

    <AndroidD8ExtraArguments>--map-diagnostics warning info</AndroidD8ExtraArguments>
    <AndroidR8ExtraArguments>--map-diagnostics warning info</AndroidR8ExtraArguments>

To solve this problem, let's create a new `$(AndroidD8IgnoreWarnings)`
MSBuild property and make use of one we already have
`$(AndroidR8IgnoreWarnings)`:

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

We can then use these item groups to pass `--map-diagnostics` as
appropriate. Developers can turn off either property to disable this
behavior.

We can then remove the weird `Regex` code added in 92bc705. The
existing tests from 92bc705 should also be sufficient for testing
this change.
@jonathanpeppers jonathanpeppers changed the title [Xamarin.Android.Build.Tasks] downgrade warning messages to info [Xamarin.Android.Build.Tasks] downgrade d8/r8 warning messages to info Dec 15, 2022
@jonathanpeppers
Copy link
Member Author

The one test failure looks unrelated:

dotnet run should succeed
Expected: True
But was:  False
...
[BT Error retrieving device SDK version. Please try again. [/Users/runner/work/1/a/TestRelease/12-15_23.39.44/temp/DotNetInstallAndRunTrueTruenet6.0-android/UnnamedProject.csproj]

@jonathanpeppers jonathanpeppers marked this pull request as ready for review December 16, 2022 15:55
Copy link
Contributor

@dellis1972 dellis1972 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a unit test which convers this to make sure the warnings are mapped to info?

@jonathanpeppers
Copy link
Member Author

The test from 92bc705, it previously had build warnings like this when enabling multi-dex:

R8 : warning : Resource 'META-INF/MANIFEST.MF' already exists.

It asserts there are 0 warnings: https://github.com/xamarin/xamarin-android/blob/d4c2a5e2ba148ea1d63fdc7f8c984642e7b5b369/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs#L282

Now it should log a message instead:

Info: Resource 'META-INF/MANIFEST.MF' already exists.

@jonpryor jonpryor merged commit b7138f1 into dotnet:main Jan 4, 2023
@jonathanpeppers jonathanpeppers deleted the D8R8WarningToInfo branch January 4, 2023 17:40
grendello added a commit to grendello/xamarin-android that referenced this pull request Jan 17, 2023
* main:
  [Xamarin.Android.Build.Tasks] skip XA1034 logic in some cases (dotnet#7680)
  [ci] Move OneLocBuild task to scheduled pipeline (dotnet#7679)
  [Mono.Android] ServerCertificateValidationCallback() and redirects (dotnet#7662)
  Bump to xamarin/Java.Interop/main@cf80deb7 (dotnet#7664)
  Localized file check-in by OneLocBuild (dotnet#7668)
  [api-merge] Correctly compute //method/@deprecated-since (dotnet#7645)
  [Xamarin.Android.Build.Tasks] _Microsoft.Android.Resource.Designer (dotnet#6427)
  [Xamarin.Android.Build.Tasks] downgrade d8/r8 `warning` messages to `info` (dotnet#7643)
  [Xamarin.Android.Build.Tasks] fix cases of missing `@(Reference)` (dotnet#7642)
  [Xamarin.Android.Build.Tasks] delay ToJniName calls in ManifestDocument (dotnet#7653)
  [Xamarin.Android.Build.Tasks] fast path for `<CheckClientHandlerType/>` (dotnet#7652)
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

R8 : warning : Missing class androidx.window.extensions.WindowExtensions
3 participants