android: [net7-rc2] Building an app in Release configuration reports incorrect duplicate types

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

net7.0-rc2

Description

Building a net6.0-android app in Release configuration causes the following errors:

C:\hostedtoolcache\windows\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.476\tools\Xamarin.Android.Common.targets(1438,3): 
warning XA4214: The managed type `Microsoft.UI.Xaml.Controls.AnimatedIcon` exists in multiple assemblies: Uno.UI, Uno.UI, Uno.UI, Uno.UI. Please refactor the managed type names in these assemblies so that they are not identical. [C:\a\1\s\UnoAppAll\UnoAppAll.Mobile\UnoAppAll.Mobile.csproj::TargetFramework=net6.0-android]

then java-related errors:

C:\hostedtoolcache\windows\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.476\tools\Xamarin.Android.Common.targets(1438,3): 
error XA4215: The Java type `crc64a5a37c43dff01024.GridViewHeaderItem` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted. [C:\a\1\s\UnoAppAll\UnoAppAll.Mobile\UnoAppAll.Mobile.csproj::TargetFramework=net6.0-android]

Steps to Reproduce

  1. dotnet new install Uno.ProjectTemplates.Dotnet
  2. dotnet new unoapp -o testapp
  3. cd testapp\testapp.Mobile
  4. dotnet build -f net6.0-android -c Release

Notice a very large number of errors after the AOT step:

C:\hostedtoolcache\windows\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.476\tools\Xamarin.Android.Common.targets(1438,3): 
warning XA4214: The managed type `Microsoft.UI.Xaml.Controls.AnimatedIcon` exists in multiple assemblies: Uno.UI, Uno.UI, Uno.UI, Uno.UI. Please refactor the managed type names in these assemblies so that they are not identical. [C:\a\1\s\UnoAppAll\UnoAppAll.Mobile\UnoAppAll.Mobile.csproj::TargetFramework=net6.0-android]

then java-related errors:

C:\hostedtoolcache\windows\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.476\tools\Xamarin.Android.Common.targets(1438,3): 
error XA4215: The Java type `crc64a5a37c43dff01024.GridViewHeaderItem` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted. [C:\a\1\s\UnoAppAll\UnoAppAll.Mobile\UnoAppAll.Mobile.csproj::TargetFramework=net6.0-android]

Did you find any workaround?

No, bumping to net7.0-android did not fix the issue. Considering the number of times the duplicate assembly is found, this would look like the number of target CPU architectures ?

Relevant log output

msbuild.zip

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (12 by maintainers)

Commits related to this issue

Most upvoted comments

With updated workloads and Uno 4.7.37 it finally works even in VS17.4.4. I am able to publish targeting .net7 with AOT enabled. šŸ˜„

šŸš€šŸš€ Thanks for the work on fixing this issue!

This fixed missed the cutoff date but should be in the next one.

The .NET 7 release branch is: https://github.com/xamarin/xamarin-android/tree/release/7.0.1xx

We have a fix (see https://github.com/xamarin/xamarin-android/pull/7477) just having issues getting the unit tests green so it can be merged.

@jeromelaban the check is done within the Task GenerateJavaStubs. https://github.com/xamarin/xamarin-android/blob/main/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs#L191

The problem is GenerateJavaStubs is getting ALL of the assemblies for each RuntimeIdentifier. So we end up with 4 entires for Uno.UI etc and others.

I guess you could write a target which runs just before the _GenerateJavaStubs target which will remove those duplicates from @(_ResolvedAssemblies) and @(_ResolvedUserMonoAndroidAssemblies) … but I’m not sure how that would effect the packaging as those same ItemGroups are used to package the final app. https://github.com/xamarin/xamarin-android/blob/main/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets#L1477

You might be able to add a filter to that target locally and make copies of those ItemGroups which you then pass to GenerateJavaStubs. (effectively replacing the @(_ResolvedAssemblies) and @(_ResolvedUserMonoAndroidAssemblies) for that target, but leaving those ItemGroups intack for the other targets.