diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildWithLibraryTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildWithLibraryTests.cs index e1083a3cef2..33f75fccbea 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildWithLibraryTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildWithLibraryTests.cs @@ -269,11 +269,7 @@ public void ProjectDependencies ([Values(true, false)] bool projectReference) }; libB.Sources.Clear (); libB.Sources.Add (new BuildItem.Source ("Foo.cs") { - TextContent = () => @"public class Foo { - public Foo () { - var bar = new Bar(); - } - }", + TextContent = () => "public class Foo : Bar { }", }); var libC = new XamarinAndroidLibraryProject () { @@ -283,7 +279,7 @@ public Foo () { }; libC.Sources.Clear (); libC.Sources.Add (new BuildItem.Source ("Bar.cs") { - TextContent = () => "public class Bar { }", + TextContent = () => "public class Bar : Java.Lang.Object { }", }); libC.Sources.Add (new BuildItem ("EmbeddedResource", "Foo.resx") { TextContent = () => InlineData.ResxWithContents ("Cancel") @@ -309,8 +305,8 @@ public Foo () { ProjectName = "AppA", IsRelease = true, Sources = { - new BuildItem.Source ("Bar.cs") { - TextContent = () => "public class Bar : Foo { }", + new BuildItem.Source ("Baz.cs") { + TextContent = () => "public class Baz : Foo { }", }, new BuildItem ("EmbeddedResource", "Foo.resx") { TextContent = () => InlineData.ResxWithContents ("Cancel") @@ -321,6 +317,10 @@ public Foo () { } }; appA.AddReference (libB); + if (!projectReference) { + // @(ProjectReference) implicits adds this reference. For `class Baz : Foo : Bar`: + appA.OtherBuildItems.Add (new BuildItem.Reference ($@"..\{libC.ProjectName}\bin\Release\{libC.TargetFramework}\{libC.ProjectName}.dll")); + } var appBuilder = CreateApkBuilder (Path.Combine (path, appA.ProjectName)); Assert.IsTrue (appBuilder.Build (appA), $"{appA.ProjectName} should succeed"); @@ -332,6 +332,17 @@ public Foo () { helper.AssertContainsEntry ($"assemblies/{libC.ProjectName}.dll"); helper.AssertContainsEntry ($"assemblies/es/{appA.ProjectName}.resources.dll"); helper.AssertContainsEntry ($"assemblies/es/{libC.ProjectName}.resources.dll"); + + var intermediate = Path.Combine (Root, appBuilder.ProjectDirectory, appA.IntermediateOutputPath); + var dexFile = Path.Combine (intermediate, "android", "bin", "classes.dex"); + FileAssert.Exists (dexFile); + + // NOTE: the crc hashes here might change one day, but if we used [Android.Runtime.Register("")] + // LibraryB.dll would have a reference to Mono.Android.dll, which invalidates the test. + string className = "Lcrc6414a4b78410c343a2/Bar;"; + Assert.IsTrue (DexUtils.ContainsClass (className, dexFile, AndroidSdkPath), $"`{dexFile}` should include `{className}`!"); + className = "Lcrc646d2d82b4d8b39bd8/Foo;"; + Assert.IsTrue (DexUtils.ContainsClass (className, dexFile, AndroidSdkPath), $"`{dexFile}` should include `{className}`!"); } [Test] diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs index 8fb845dd9df..dc768408fe3 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs @@ -277,8 +277,13 @@ public static void LogWarning (object log, string msg, params object [] args) #if MSBUILD public static bool IsMonoAndroidAssembly (ITaskItem assembly) { + // NOTE: look for both MonoAndroid and Android var tfi = assembly.GetMetadata ("TargetFrameworkIdentifier"); - if (string.Compare (tfi, "MonoAndroid", StringComparison.OrdinalIgnoreCase) == 0) + if (tfi.IndexOf ("Android", StringComparison.OrdinalIgnoreCase) != -1) + return true; + + var tpi = assembly.GetMetadata ("TargetPlatformIdentifier"); + if (tpi.IndexOf ("Android", StringComparison.OrdinalIgnoreCase) != -1) return true; var hasReference = assembly.GetMetadata ("HasMonoAndroidReference");