Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Don't report duplicate type if the mvid…
Browse files Browse the repository at this point in the history
… is the same.

Fixes dotnet#7473

With the new build system under `dotnet` we can end up with duplicate
assemblies for different `RuntimeIdentifiers`. This can cause the
`GenerateJavaStubs` task to mistakenly report duplicate types.

```
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]
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]
```

We should ignore these duplicates is the `mvid` of the the type module is
the same. If it is then they will be from the same assembly.
  • Loading branch information
dellis1972 committed Nov 16, 2022
1 parent 0ee174c commit 19f6a56
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ void Run (DirectoryAssemblyResolver res, bool useMarshalMethods)
if ((!useMarshalMethods && !userAssemblies.ContainsKey (td.Module.Assembly.Name.Name)) || JavaTypeScanner.ShouldSkipJavaCallableWrapperGeneration (td, cache)) {
continue;
}

javaTypes.Add (td);
}

Expand Down Expand Up @@ -272,6 +271,7 @@ void Run (DirectoryAssemblyResolver res, bool useMarshalMethods)

using (var acw_map = MemoryStreamPool.Shared.CreateStreamWriter ()) {
foreach (TypeDefinition type in javaTypes) {
string mvid = type.Module.Mvid.ToString ();
string managedKey = type.FullName.Replace ('/', '.');
string javaKey = JavaNativeTypeManager.ToJniName (type, cache).Replace ('/', '.');

Expand All @@ -283,16 +283,20 @@ void Run (DirectoryAssemblyResolver res, bool useMarshalMethods)
TypeDefinition conflict;
bool hasConflict = false;
if (managed.TryGetValue (managedKey, out conflict)) {
if (!managedConflicts.TryGetValue (managedKey, out var list))
managedConflicts.Add (managedKey, list = new List<string> { conflict.GetPartialAssemblyName (cache) });
list.Add (type.GetPartialAssemblyName (cache));
if (!conflict.Module.Mvid.Equals(mvid)) {
if (!managedConflicts.TryGetValue (managedKey, out var list))
managedConflicts.Add (managedKey, list = new List<string> { conflict.GetPartialAssemblyName (cache) });
list.Add (type.GetPartialAssemblyName (cache));
}
hasConflict = true;
}
if (java.TryGetValue (javaKey, out conflict)) {
if (!javaConflicts.TryGetValue (javaKey, out var list))
javaConflicts.Add (javaKey, list = new List<string> { conflict.GetAssemblyQualifiedName (cache) });
list.Add (type.GetAssemblyQualifiedName (cache));
success = false;
if (!conflict.Module.Mvid.Equals(mvid)) {
if (!javaConflicts.TryGetValue (javaKey, out var list))
javaConflicts.Add (javaKey, list = new List<string> { conflict.GetAssemblyQualifiedName (cache) });
list.Add (type.GetAssemblyQualifiedName (cache));
success = false;
}
hasConflict = true;
}
if (!hasConflict) {
Expand Down

0 comments on commit 19f6a56

Please sign in to comment.