Skip to content
New issue

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

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

Already on GitHub? # to your account

[Xamarin.Android.Build.Tasks] Don't report duplicate type if the AssemblyName is the same. #7477

Merged
merged 5 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 11 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 @@ -283,16 +282,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.Name.Equals (type.Module.Name)) {
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.Name.Equals (type.Module.Name)) {
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
Original file line number Diff line number Diff line change
Expand Up @@ -509,5 +509,39 @@ public void AndroidUseNegotiateAuthentication ([Values (true, false, null)] bool
}
}
}

[Test]
public void DoNotErrorOnPerArchJavaTypeDuplicates ()
{
if (!Builder.UseDotNet)
Assert.Ignore ("Test only valid on .NET");

var path = Path.Combine (Root, "temp", TestName);
var lib = new XamarinAndroidLibraryProject { IsRelease = true, ProjectName = "Lib1" };
lib.SetProperty ("IsTrimmable", "true");
lib.Sources.Add (new BuildItem.Source ("Library1.cs") {
TextContent = () => @"
namespace Lib1;
public class Library1 : Java.Lang.Object {
private static bool Is64Bits = IntPtr.Size >= 8;

public static bool Is64 () {
return Is64Bits;
}
}",
});
var proj = new XamarinAndroidApplicationProject { IsRelease = true, ProjectName = "App1" };
proj.References.Add(new BuildItem.ProjectReference (Path.Combine ("..", "Lib1", "Lib1.csproj"), "Lib1"));
proj.MainActivity = proj.DefaultMainActivity.Replace (
"base.OnCreate (bundle);",
"base.OnCreate (bundle);\n" +
"if (Lib1.Library1.Is64 ()) Console.WriteLine (\"Hello World!\");");


using var lb = CreateDllBuilder (Path.Combine (path, "Lib1"));
using var b = CreateApkBuilder (Path.Combine (path, "App1"));
Assert.IsTrue (lb.Build (lib), "build should have succeeded.");
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
}
}
}