Skip to content

Commit cba760c

Browse files
committed
Add Unit test
1 parent d4668c6 commit cba760c

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,15 @@ void Run (DirectoryAssemblyResolver res, bool useMarshalMethods)
282282
TypeDefinition conflict;
283283
bool hasConflict = false;
284284
if (managed.TryGetValue (managedKey, out conflict)) {
285-
if (!conflict.Module.Mvid.Equals(type.Module.Mvid)) {
285+
if (!conflict.Module.Name.Equals(type.Module.Name)) {
286286
if (!managedConflicts.TryGetValue (managedKey, out var list))
287287
managedConflicts.Add (managedKey, list = new List<string> { conflict.GetPartialAssemblyName (cache) });
288288
list.Add (type.GetPartialAssemblyName (cache));
289289
}
290290
hasConflict = true;
291291
}
292292
if (java.TryGetValue (javaKey, out conflict)) {
293-
if (!conflict.Module.Mvid.Equals(type.Module.Mvid)) {
293+
if (!conflict.Module.Name.Equals(type.Module.Name)) {
294294
if (!javaConflicts.TryGetValue (javaKey, out var list))
295295
javaConflicts.Add (javaKey, list = new List<string> { conflict.GetAssemblyQualifiedName (cache) });
296296
list.Add (type.GetAssemblyQualifiedName (cache));

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/LinkerTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,5 +509,41 @@ public void AndroidUseNegotiateAuthentication ([Values (true, false, null)] bool
509509
}
510510
}
511511
}
512+
513+
[Test]
514+
public void DoNotErrorOnPerArchJavaTypeDuplicates ()
515+
{
516+
if (!Builder.UseDotNet)
517+
Assert.Ignore ("Test only valid on .NET");
518+
519+
var path = Path.Combine (Root, "temp", TestName);
520+
var lib = new XamarinAndroidLibraryProject { IsRelease = true, ProjectName = "Lib1" };
521+
lib.SetProperty ("IsTrimmable", "true");
522+
lib.Sources.Add (new BuildItem.Source ("Library1.cs") {
523+
TextContent = () => @"
524+
namespace Lib1;
525+
public class Library1 : Java.Lang.Object {
526+
private static bool Is64Bits = IntPtr.Size >= 8;
527+
528+
public static bool Is64 () {
529+
return Is64Bits;
530+
}
531+
}",
532+
});
533+
var proj = new XamarinAndroidApplicationProject { IsRelease = true, ProjectName = "App1" };
534+
proj.References.Add(new BuildItem.ProjectReference (Path.Combine ("..", "Lib1", "Lib1.csproj"), "Lib1"));
535+
proj.MainActivity = proj.DefaultMainActivity.Replace (
536+
"base.OnCreate (bundle);",
537+
"base.OnCreate (bundle);\n" +
538+
"if (Lib1.Library1.Is64 ()) Console.WriteLine (\"Hello World!\");");
539+
540+
541+
using (var lb = CreateDllBuilder (Path.Combine (path, "Lib1"))) {
542+
using (var b = CreateApkBuilder (Path.Combine (path, "App1"))) {
543+
Assert.IsTrue (lb.Build (lib), "build should have succeeded.");
544+
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
545+
}
546+
}
547+
}
512548
}
513549
}

0 commit comments

Comments
 (0)