Skip to content

Commit 52e2d7d

Browse files
committed
[Xamarin.Android.Build.Tasks] Don't report duplicate type if the mvid is the same.
Fixes #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.
1 parent 5f3deea commit 52e2d7d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ void Run (DirectoryAssemblyResolver res, bool useMarshalMethods)
217217
if ((!useMarshalMethods && !userAssemblies.ContainsKey (td.Module.Assembly.Name.Name)) || JavaTypeScanner.ShouldSkipJavaCallableWrapperGeneration (td, cache)) {
218218
continue;
219219
}
220-
221220
javaTypes.Add (td);
222221
}
223222

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

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

@@ -283,16 +283,20 @@ void Run (DirectoryAssemblyResolver res, bool useMarshalMethods)
283283
TypeDefinition conflict;
284284
bool hasConflict = false;
285285
if (managed.TryGetValue (managedKey, out conflict)) {
286-
if (!managedConflicts.TryGetValue (managedKey, out var list))
287-
managedConflicts.Add (managedKey, list = new List<string> { conflict.GetPartialAssemblyName (cache) });
288-
list.Add (type.GetPartialAssemblyName (cache));
286+
if (!conflict.Module.Mvid.Equals(mvid)) {
287+
if (!managedConflicts.TryGetValue (managedKey, out var list))
288+
managedConflicts.Add (managedKey, list = new List<string> { conflict.GetPartialAssemblyName (cache) });
289+
list.Add (type.GetPartialAssemblyName (cache));
290+
}
289291
hasConflict = true;
290292
}
291293
if (java.TryGetValue (javaKey, out conflict)) {
292-
if (!javaConflicts.TryGetValue (javaKey, out var list))
293-
javaConflicts.Add (javaKey, list = new List<string> { conflict.GetAssemblyQualifiedName (cache) });
294-
list.Add (type.GetAssemblyQualifiedName (cache));
295-
success = false;
294+
if (!conflict.Module.Mvid.Equals(mvid)) {
295+
if (!javaConflicts.TryGetValue (javaKey, out var list))
296+
javaConflicts.Add (javaKey, list = new List<string> { conflict.GetAssemblyQualifiedName (cache) });
297+
list.Add (type.GetAssemblyQualifiedName (cache));
298+
success = false;
299+
}
296300
hasConflict = true;
297301
}
298302
if (!hasConflict) {

0 commit comments

Comments
 (0)