From ae4f229c6a43a2e57fa801a136c8697dcfbc2ca1 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Wed, 2 Aug 2023 12:26:32 -0400 Subject: [PATCH] [tests] Remove duplicates from XASdkTests (#8214) I've spent some time reviewing tests in `XASdkTests`, `BuildTest`, and `BuildTest2`. Tests from `XASdkTests` have been migrated to other fixtures or removed where applicable. * DotNetBuildXamarinForms has been removed and merged into CheckMonoComponentsMask. * DotNetIncremental has been removed and merged into BuildIncrementalAot. * DotNetDesignTimeBuild has been renamed to DesignTimeBuildSignAndroidPackage. * BenchmarkDotNet has been removed and merged into BuildHasNoWarnings. * BuildApplicationWithJavaSource has been removed due to existing coverage of .java file inclusion elsewhere. * BuildReleaseApplicationWithNugetPackages has been removed due to existing coverage in GenerateLibraryResourcesTests. * BuildAfterAddingNuget has been removed as the same scenario is covered in BuildAfterUpgradingNuget. * ValidateJavaVersion has been removed as .NET Android requires JDK 11+, which is not covered by any of the legacy parameters. --- .../AndroidUpdateResourcesTest.cs | 45 + .../Xamarin.Android.Build.Tests/AotTests.cs | 42 + .../BindingBuildTest.cs | 84 +- .../BuildTest.TestCaseSource.cs | 99 ++ .../Xamarin.Android.Build.Tests/BuildTest.cs | 933 +++------------ .../Xamarin.Android.Build.Tests/BuildTest2.cs | 1 + .../BuildWithLibraryTests.cs | 887 ++++++++++++++ .../IncrementalBuildTest.cs | 57 +- .../InvalidConfigTests.cs | 114 ++ .../PackagingTest.cs | 41 + .../Xamarin.Android.Build.Tests/WearTests.cs | 25 + .../Xamarin.Android.Build.Tests/XASdkTests.cs | 1017 +---------------- 12 files changed, 1537 insertions(+), 1808 deletions(-) create mode 100644 src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildWithLibraryTests.cs create mode 100644 src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/InvalidConfigTests.cs diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs index dd811c1d880..c653639bfd0 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs @@ -6,6 +6,7 @@ using System.Text.RegularExpressions; using System.Xml.Linq; using Microsoft.Build.Framework; +using Mono.Cecil; using NUnit.Framework; using Xamarin.Android.Tools; using Xamarin.ProjectTools; @@ -648,6 +649,50 @@ public void CheckOldResourceDesignerWithWrongCasingIsRemoved ([Values (true, fal } } + [Test] + public void GenerateResourceDesigner_false([Values (false, true)] bool useDesignerAssembly) + { + var proj = new XamarinAndroidApplicationProject { + EnableDefaultItems = true, + Sources = { + new AndroidItem.AndroidResource (() => "Resources\\drawable\\foo.png") { + BinaryContent = () => XamarinAndroidCommonProject.icon_binary_mdpi, + }, + } + }; + proj.SetProperty (KnownProperties.OutputType, "Library"); + + // Turn off Resource.designer.cs and remove usage of it + proj.SetProperty ("AndroidGenerateResourceDesigner", "false"); + if (!useDesignerAssembly) + proj.SetProperty ("AndroidUseDesignerAssembly", "false"); + proj.MainActivity = proj.DefaultMainActivity + .Replace ("Resource.Layout.Main", "0") + .Replace ("Resource.Id.myButton", "0"); + + var builder = CreateDllBuilder (); + Assert.IsTrue (builder.RunTarget(proj, "CoreCompile", parameters: new string[] { "BuildingInsideVisualStudio=true" }), "Designtime build should succeed."); + var intermediate = Path.Combine (Root, builder.ProjectDirectory, proj.IntermediateOutputPath); + var resource_designer_cs = Path.Combine (intermediate, "designtime", "Resource.designer.cs"); + if (useDesignerAssembly) + resource_designer_cs = Path.Combine (intermediate, "__Microsoft.Android.Resource.Designer.cs"); + FileAssert.DoesNotExist (resource_designer_cs); + + Assert.IsTrue (builder.Build (proj), "build should succeed"); + + resource_designer_cs = Path.Combine (intermediate, "Resource.designer.cs"); + if (useDesignerAssembly) + resource_designer_cs = Path.Combine (intermediate, "__Microsoft.Android.Resource.Designer.cs"); + FileAssert.DoesNotExist (resource_designer_cs); + + var assemblyPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll"); + FileAssert.Exists (assemblyPath); + using var assembly = AssemblyDefinition.ReadAssembly (assemblyPath); + var typeName = $"{proj.ProjectName}.Resource"; + var type = assembly.MainModule.GetType (typeName); + Assert.IsNull (type, $"{assemblyPath} should *not* contain {typeName}"); + } + [Test] public void CheckThatXA1034IsRaisedForInvalidConfiguration ([Values (true, false)] bool isRelease) { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs index 37f0fcfcf8b..db5da19d657 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AotTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -8,6 +9,7 @@ using NUnit.Framework; using Xamarin.ProjectTools; using Xamarin.Android.Build; +using Xamarin.Android.Tasks; namespace Xamarin.Android.Build.Tests { @@ -486,5 +488,45 @@ public void AotAssembliesInIDE () Assert.IsNotNull (entry, $"{path} should be in {apk}", abi); } } + + [Test] + public void CheckWhetherLibcAndLibmAreReferencedInAOTLibraries () + { + if (IsWindows) + Assert.Ignore ("https://github.com/dotnet/runtime/issues/88625"); + + var proj = new XamarinAndroidApplicationProject { + IsRelease = true, + EmbedAssembliesIntoApk = true, + AotAssemblies = true, + }; + proj.SetProperty ("EnableLLVM", "True"); + + var abis = new [] { "arm64-v8a", "x86_64" }; + proj.SetAndroidSupportedAbis (abis); + + var libPaths = new List (); + if (Builder.UseDotNet) { + libPaths.Add (Path.Combine ("android-arm64", "aot", "Mono.Android.dll.so")); + libPaths.Add (Path.Combine ("android-x64", "aot", "Mono.Android.dll.so")); + } else { + libPaths.Add (Path.Combine ("aot", "arm64-v8a", "libaot-Mono.Android.dll.so")); + libPaths.Add (Path.Combine ("aot", "x86_64", "libaot-Mono.Android.dll.so")); + } + + using (var b = CreateApkBuilder ()) { + Assert.IsTrue (b.Build (proj), "Build should have succeeded."); + string objPath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath); + + foreach (string libPath in libPaths) { + string lib = Path.Combine (objPath, libPath); + + Assert.IsTrue (File.Exists (lib), $"Library {lib} should exist on disk"); + Assert.IsTrue (ELFHelper.ReferencesLibrary (lib, "libc.so"), $"Library {lib} should reference libc.so"); + Assert.IsTrue (ELFHelper.ReferencesLibrary (lib, "libm.so"), $"Library {lib} should reference libm.so"); + } + } + } + } } diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs index 99142a257c8..70e42e8c71f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs @@ -12,8 +12,53 @@ namespace Xamarin.Android.Build.Tests { [Parallelizable (ParallelScope.Children)] - public class BindingBuildTest : BaseTest { -#pragma warning disable 414 + public class BindingBuildTest : BaseTest + { + [Test] + public void DotNetBuildBinding () + { + var proj = new XamarinAndroidLibraryProject () { + EnableDefaultItems = true, + }; + // Both transform files should be applied + proj.Sources.Add (new AndroidItem.TransformFile ("Transforms.xml") { + TextContent = () => +@" + FooBar +", + }); + proj.Sources.Add (new AndroidItem.TransformFile ("Transforms\\Metadata.xml") { + TextContent = () => +@" + MSBuildTest +", + }); + proj.Sources.Add (new AndroidItem.AndroidLibrary ("javaclasses.jar") { + BinaryContent = () => ResourceData.JavaSourceJarTestJar, + }); + proj.OtherBuildItems.Add (new BuildItem ("JavaSourceJar", "javaclasses-sources.jar") { + BinaryContent = () => ResourceData.JavaSourceJarTestSourcesJar, + }); + proj.OtherBuildItems.Add (new AndroidItem.AndroidJavaSource ("JavaSourceTestExtension.java") { + Encoding = Encoding.ASCII, + TextContent = () => ResourceData.JavaSourceTestExtension, + Metadata = { { "Bind", "True"} }, + }); + var builder = CreateDllBuilder (); + Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed"); + + var assemblyPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, "UnnamedProject.dll"); + FileAssert.Exists (assemblyPath); + using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) { + var typeName = "MSBuildTest.JavaSourceJarTest"; + var type = assembly.MainModule.GetType (typeName); + Assert.IsNotNull (type, $"{assemblyPath} should contain {typeName}"); + typeName = "MSBuildTest.JavaSourceTestExtension"; + type = assembly.MainModule.GetType (typeName); + Assert.IsNotNull (type, $"{assemblyPath} should contain {typeName}"); + } + } + static object [] ClassParseOptions = new object [] { new object[] { /* classParser */ "class-parse", @@ -22,7 +67,7 @@ public class BindingBuildTest : BaseTest { [Test] [TestCaseSource (nameof (ClassParseOptions))] - public void BuildBasicBindingLibrary (string classParser) + public void BindingLibraryIncremental (string classParser) { var targets = new List { "_ExportJarToXml", @@ -475,6 +520,39 @@ public void JavaSourceJar () } } + [Test] + public void AppWithSingleJar () + { + var proj = new XamarinAndroidApplicationProject { + EnableDefaultItems = true, + Sources = { + new AndroidItem.AndroidLibrary ("Jars\\javaclasses.jar") { + BinaryContent = () => ResourceData.JavaSourceJarTestJar, + } + } + }; + + var builder = CreateApkBuilder (); + Assert.IsTrue (builder.Build (proj), "first build should succeed"); + + var assemblyPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll"); + var typeName = "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceJarTest"; + FileAssert.Exists (assemblyPath); + using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) { + Assert.IsNotNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should contain {typeName}"); + } + + // Remove the @(AndroidLibrary) & build again + proj.Sources.RemoveAt (proj.Sources.Count - 1); + Directory.Delete (Path.Combine (Root, builder.ProjectDirectory, "Jars"), recursive: true); + Assert.IsTrue (builder.Build (proj), "second build should succeed"); + + FileAssert.Exists (assemblyPath); + using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) { + Assert.IsNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should *not* contain {typeName}"); + } + } + [Test] [TestCaseSource (nameof (ClassParseOptions))] public void DesignTimeBuild (string classParser) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.TestCaseSource.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.TestCaseSource.cs index f0f22e2ef53..29a390c9835 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.TestCaseSource.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.TestCaseSource.cs @@ -11,6 +11,105 @@ namespace Xamarin.Android.Build.Tests { public partial class BuildTest : BaseTest { + static readonly object [] DotNetBuildSource = new object [] { + new object [] { + /* runtimeIdentifiers */ "android-arm", + /* isRelease */ false, + /* aot */ false, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm", + /* isRelease */ false, + /* aot */ false, + /* usesAssemblyStore */ true, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm64", + /* isRelease */ false, + /* aot */ false, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-x86", + /* isRelease */ false, + /* aot */ false, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-x64", + /* isRelease */ false, + /* aot */ false, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm", + /* isRelease */ true, + /* aot */ false, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm", + /* isRelease */ true, + /* aot */ false, + /* usesAssemblyStore */ true, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm", + /* isRelease */ true, + /* aot */ true, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm", + /* isRelease */ true, + /* aot */ true, + /* usesAssemblyStore */ true, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm64", + /* isRelease */ true, + /* aot */ false, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64", + /* isRelease */ false, + /* aot */ false, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64", + /* isRelease */ false, + /* aot */ false, + /* usesAssemblyStore */ true, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm;android-arm64;android-x86", + /* isRelease */ true, + /* aot */ false, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64", + /* isRelease */ true, + /* aot */ false, + /* usesAssemblyStore */ false, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64", + /* isRelease */ true, + /* aot */ false, + /* usesAssemblyStore */ true, + }, + new object [] { + /* runtimeIdentifiers */ "android-arm;android-arm64;android-x86;android-x64", + /* isRelease */ true, + /* aot */ true, + /* usesAssemblyStore */ false, + }, + }; + #pragma warning disable 414 static object [] RuntimeChecks () => new object [] { new object[] { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index 149caaf74be..1ea69378427 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -22,6 +22,146 @@ namespace Xamarin.Android.Build.Tests [Parallelizable (ParallelScope.Children)] public partial class BuildTest : BaseTest { + [Test] + [Category ("SmokeTests")] + [TestCaseSource (nameof (DotNetBuildSource))] + [NonParallelizable] // On MacOS, parallel /restore causes issues + public void DotNetBuild (string runtimeIdentifiers, bool isRelease, bool aot, bool usesAssemblyStore) + { + var proj = new XamarinAndroidApplicationProject { + IsRelease = isRelease, + EnableDefaultItems = true, + ExtraNuGetConfigSources = { + // Microsoft.AspNetCore.Components.WebView is not in dotnet-public + "https://api.nuget.org/v3/index.json", + }, + PackageReferences = { + new Package { Id = "Xamarin.AndroidX.AppCompat", Version = "1.3.1.1" }, + // Using * here, so we explicitly get newer packages + new Package { Id = "Microsoft.AspNetCore.Components.WebView", Version = "6.0.0-*" }, + new Package { Id = "Microsoft.Extensions.FileProviders.Embedded", Version = "6.0.0-*" }, + new Package { Id = "Microsoft.JSInterop", Version = "6.0.0-*" }, + new Package { Id = "System.Text.Json", Version = "6.0.0-*" }, + }, + Sources = { + new BuildItem ("EmbeddedResource", "Foo.resx") { + TextContent = () => InlineData.ResxWithContents ("Cancel") + }, + new BuildItem ("EmbeddedResource", "Foo.es.resx") { + TextContent = () => InlineData.ResxWithContents ("Cancelar") + }, + new AndroidItem.TransformFile ("Transforms.xml") { + // Remove two methods that introduced warnings: + // Com.Balysv.Material.Drawable.Menu.MaterialMenuView.cs(214,30): warning CS0114: 'MaterialMenuView.OnRestoreInstanceState(IParcelable)' hides inherited member 'View.OnRestoreInstanceState(IParcelable?)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword. + // Com.Balysv.Material.Drawable.Menu.MaterialMenuView.cs(244,56): warning CS0114: 'MaterialMenuView.OnSaveInstanceState()' hides inherited member 'View.OnSaveInstanceState()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword. + TextContent = () => "", + }, + new AndroidItem.AndroidLibrary ("material-menu-1.1.0.aar") { + WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar" + }, + } + }; + proj.MainActivity = proj.DefaultMainActivity.Replace (": Activity", ": AndroidX.AppCompat.App.AppCompatActivity"); + proj.SetProperty ("AndroidUseAssemblyStore", usesAssemblyStore.ToString ()); + proj.SetProperty ("RunAOTCompilation", aot.ToString ()); + proj.OtherBuildItems.Add (new AndroidItem.InputJar ("javaclasses.jar") { + BinaryContent = () => ResourceData.JavaSourceJarTestJar, + }); + proj.OtherBuildItems.Add (new BuildItem ("JavaSourceJar", "javaclasses-sources.jar") { + BinaryContent = () => ResourceData.JavaSourceJarTestSourcesJar, + }); + proj.OtherBuildItems.Add (new AndroidItem.AndroidJavaSource ("JavaSourceTestExtension.java") { + Encoding = Encoding.ASCII, + TextContent = () => ResourceData.JavaSourceTestExtension, + Metadata = { { "Bind", "True"} }, + }); + if (!runtimeIdentifiers.Contains (";")) { + proj.SetProperty (KnownProperties.RuntimeIdentifier, runtimeIdentifiers); + } else { + proj.SetProperty (KnownProperties.RuntimeIdentifiers, runtimeIdentifiers); + } + + var builder = CreateApkBuilder (); + Assert.IsTrue (builder.Build (proj), "`dotnet build` should succeed"); + builder.AssertHasNoWarnings (); + + var outputPath = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath); + var intermediateOutputPath = Path.Combine (Root, builder.ProjectDirectory, proj.IntermediateOutputPath); + if (!runtimeIdentifiers.Contains (";")) { + outputPath = Path.Combine (outputPath, runtimeIdentifiers); + intermediateOutputPath = Path.Combine (intermediateOutputPath, runtimeIdentifiers); + } + + var files = Directory.EnumerateFileSystemEntries (outputPath) + .Select (Path.GetFileName) + .OrderBy (f => f, StringComparer.OrdinalIgnoreCase) + .ToArray (); + var expectedFiles = new List { + $"{proj.PackageName}-Signed.apk", + "es", + $"{proj.ProjectName}.dll", + $"{proj.ProjectName}.pdb", + $"{proj.ProjectName}.runtimeconfig.json", + $"{proj.ProjectName}.xml", + }; + if (isRelease) { + expectedFiles.Add ($"{proj.PackageName}.aab"); + expectedFiles.Add ($"{proj.PackageName}-Signed.aab"); + } else { + expectedFiles.Add ($"{proj.PackageName}.apk"); + expectedFiles.Add ($"{proj.PackageName}-Signed.apk.idsig"); + } + + expectedFiles.Sort(StringComparer.OrdinalIgnoreCase); + + CollectionAssert.AreEquivalent (expectedFiles, files, $"Expected: {string.Join (";", expectedFiles)}\n Found: {string.Join (";", files)}"); + + var assemblyPath = Path.Combine (outputPath, $"{proj.ProjectName}.dll"); + FileAssert.Exists (assemblyPath); + using (var assembly = AssemblyDefinition.ReadAssembly (assemblyPath)) { + var typeName = "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceJarTest"; + Assert.IsNotNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should contain {typeName}"); + typeName = "Com.Balysv.Material.Drawable.Menu.MaterialMenuView"; + Assert.IsNotNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should contain {typeName}"); + typeName = "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceTestExtension"; + Assert.IsNotNull (assembly.MainModule.GetType (typeName), $"{assemblyPath} should contain {typeName}"); + } + + var rids = runtimeIdentifiers.Split (';'); + + // Check AndroidManifest.xml + var manifestPath = Path.Combine (intermediateOutputPath, "android", "AndroidManifest.xml"); + FileAssert.Exists (manifestPath); + var manifest = XDocument.Load (manifestPath); + XNamespace ns = "http://schemas.android.com/apk/res/android"; + var uses_sdk = manifest.Root.Element ("uses-sdk"); + Assert.AreEqual ("21", uses_sdk.Attribute (ns + "minSdkVersion").Value); + Assert.AreEqual (XABuildConfig.AndroidDefaultTargetDotnetApiLevel.ToString(), + uses_sdk.Attribute (ns + "targetSdkVersion").Value); + + bool expectEmbeddedAssembies = !(CommercialBuildAvailable && !isRelease); + var apkPath = Path.Combine (outputPath, $"{proj.PackageName}-Signed.apk"); + FileAssert.Exists (apkPath); + var helper = new ArchiveAssemblyHelper (apkPath, usesAssemblyStore, rids); + helper.AssertContainsEntry ($"assemblies/{proj.ProjectName}.dll", shouldContainEntry: expectEmbeddedAssembies); + helper.AssertContainsEntry ($"assemblies/{proj.ProjectName}.pdb", shouldContainEntry: !CommercialBuildAvailable && !isRelease); + helper.AssertContainsEntry ($"assemblies/Mono.Android.dll", shouldContainEntry: expectEmbeddedAssembies); + helper.AssertContainsEntry ($"assemblies/es/{proj.ProjectName}.resources.dll", shouldContainEntry: expectEmbeddedAssembies); + foreach (var abi in rids.Select (AndroidRidAbiHelper.RuntimeIdentifierToAbi)) { + helper.AssertContainsEntry ($"lib/{abi}/libmonodroid.so"); + helper.AssertContainsEntry ($"lib/{abi}/libmonosgen-2.0.so"); + if (rids.Length > 1) { + helper.AssertContainsEntry ($"assemblies/{abi}/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies); + } else { + helper.AssertContainsEntry ("assemblies/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies); + } + if (aot) { + helper.AssertContainsEntry ($"lib/{abi}/libaot-{proj.ProjectName}.dll.so"); + helper.AssertContainsEntry ($"lib/{abi}/libaot-Mono.Android.dll.so"); + } + } + } + static object [] MonoComponentMaskChecks () => new object [] { new object[] { true, // enableProfiler @@ -61,18 +201,19 @@ public void CheckMonoComponentsMask (bool enableProfiler, bool useInterpreter, b return; } - var proj = new XamarinAndroidApplicationProject () { + var proj = new XamarinFormsAndroidApplicationProject () { IsRelease = !debugBuild, }; proj.SetProperty (proj.ActiveConfigurationProperties, "AndroidEnableProfiler", enableProfiler.ToString ()); - proj.SetProperty (proj.ActiveConfigurationProperties, "AndroidUseInterpreter", useInterpreter.ToString ()); + proj.SetProperty (proj.ActiveConfigurationProperties, "UseInterpreter", useInterpreter.ToString ()); var abis = new [] { "armeabi-v7a", "x86" }; proj.SetAndroidSupportedAbis (abis); using (var b = CreateApkBuilder ()) { Assert.IsTrue (b.Build (proj), "Build should have succeeded."); + b.AssertHasNoWarnings (); string objPath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath); List envFiles = EnvironmentHelper.GatherEnvironmentFiles (objPath, String.Join (";", abis), true); @@ -82,45 +223,6 @@ public void CheckMonoComponentsMask (bool enableProfiler, bool useInterpreter, b } } - [Test] - public void CheckWhetherLibcAndLibmAreReferencedInAOTLibraries () - { - if (IsWindows) - Assert.Ignore ("https://github.com/dotnet/runtime/issues/88625"); - - var proj = new XamarinAndroidApplicationProject { - IsRelease = true, - EmbedAssembliesIntoApk = true, - AotAssemblies = true, - }; - proj.SetProperty ("EnableLLVM", "True"); - - var abis = new [] { "arm64-v8a", "x86_64" }; - proj.SetAndroidSupportedAbis (abis); - - var libPaths = new List (); - if (Builder.UseDotNet) { - libPaths.Add (Path.Combine ("android-arm64", "aot", "Mono.Android.dll.so")); - libPaths.Add (Path.Combine ("android-x64", "aot", "Mono.Android.dll.so")); - } else { - libPaths.Add (Path.Combine ("aot", "arm64-v8a", "libaot-Mono.Android.dll.so")); - libPaths.Add (Path.Combine ("aot", "x86_64", "libaot-Mono.Android.dll.so")); - } - - using (var b = CreateApkBuilder ()) { - Assert.IsTrue (b.Build (proj), "Build should have succeeded."); - string objPath = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath); - - foreach (string libPath in libPaths) { - string lib = Path.Combine (objPath, libPath); - - Assert.IsTrue (File.Exists (lib), $"Library {lib} should exist on disk"); - Assert.IsTrue (ELFHelper.ReferencesLibrary (lib, "libc.so"), $"Library {lib} should reference libc.so"); - Assert.IsTrue (ELFHelper.ReferencesLibrary (lib, "libm.so"), $"Library {lib} should reference libm.so"); - } - } - } - static object [] CheckAssemblyCountsSource = new object [] { new object[] { /*isRelease*/ false, @@ -311,162 +413,6 @@ public void CheckSequencePointGeneration (bool isRelease, bool monoSymbolArchive } } - [Test] - [NonParallelizable] - public void BuildWithNativeLibraries ([Values (true, false)] bool isRelease) - { - var dll = new XamarinAndroidLibraryProject () { - ProjectName = "Library1", - IsRelease = isRelease, - OtherBuildItems = { - new AndroidItem.EmbeddedNativeLibrary ("foo\\armeabi-v7a\\libtest.so") { - BinaryContent = () => new byte[10], - MetadataValues = "Link=libs\\armeabi-v7a\\libtest.so", - }, - new AndroidItem.EmbeddedNativeLibrary ("foo\\x86\\libtest.so") { - BinaryContent = () => new byte[10], - MetadataValues = "Link=libs\\x86\\libtest.so", - }, - }, - }; - var dll2 = new XamarinAndroidLibraryProject () { - ProjectName = "Library2", - IsRelease = isRelease, - References = { - new BuildItem ("ProjectReference","..\\Library1\\Library1.csproj"), - }, - OtherBuildItems = { - new AndroidItem.EmbeddedNativeLibrary ("foo\\armeabi-v7a\\libtest1.so") { - BinaryContent = () => new byte[10], - MetadataValues = "Link=libs\\armeabi-v7a\\libtest1.so", - }, - new AndroidItem.EmbeddedNativeLibrary ("foo\\x86\\libtest1.so") { - BinaryContent = () => new byte[10], - MetadataValues = "Link=libs\\x86\\libtest1.so", - }, - }, - }; - var proj = new XamarinAndroidApplicationProject () { - IsRelease = isRelease, - References = { - new BuildItem ("ProjectReference","..\\Library1\\Library1.csproj"), - new BuildItem ("ProjectReference","..\\Library2\\Library2.csproj"), - }, - OtherBuildItems = { - new AndroidItem.AndroidNativeLibrary ("armeabi-v7a\\libRSSupport.so") { - BinaryContent = () => new byte[10], - }, - }, - PackageReferences = { - KnownPackages.Xamarin_Android_Support_v8_RenderScript_28_0_0_3, - } - }; - proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86"); - if (!Builder.UseDotNet) { - //NOTE: Mono.Data.Sqlite and Mono.Posix do not exist in .NET 5+ - proj.References.Add (new BuildItem.Reference ("Mono.Data.Sqlite")); - proj.References.Add (new BuildItem.Reference ("Mono.Posix")); - proj.MainActivity = proj.DefaultMainActivity.Replace ("int count = 1;", @"int count = 1; -Mono.Data.Sqlite.SqliteConnection connection = null; -Mono.Unix.UnixFileInfo fileInfo = null;"); - } - var path = Path.Combine (Root, "temp", string.Format ("BuildWithNativeLibraries_{0}", isRelease)); - using (var b1 = CreateDllBuilder (Path.Combine (path, dll2.ProjectName))) { - Assert.IsTrue (b1.Build (dll2), "Build should have succeeded."); - using (var b = CreateDllBuilder (Path.Combine (path, dll.ProjectName))) { - Assert.IsTrue (b.Build (dll), "Build should have succeeded."); - using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName))) { - Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); - var apk = Path.Combine (Root, builder.ProjectDirectory, - proj.OutputPath, $"{proj.PackageName}-Signed.apk"); - FileAssert.Exists (apk); - Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, "warning XA4301: APK already contains the item lib/armeabi-v7a/libRSSupport.so; ignoring."), - "warning about skipping libRSSupport.so should have been raised"); - using (var zipFile = ZipHelper.OpenZip (apk)) { - var data = ZipHelper.ReadFileFromZip (zipFile, "lib/x86/libtest.so"); - Assert.IsNotNull (data, "libtest.so for x86 should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/armeabi-v7a/libtest.so"); - Assert.IsNotNull (data, "libtest.so for armeabi-v7a should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/x86/libtest1.so"); - Assert.IsNotNull (data, "libtest1.so for x86 should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/armeabi-v7a/libtest1.so"); - Assert.IsNotNull (data, "libtest1.so for armeabi-v7a should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/armeabi-v7a/libRSSupport.so"); - Assert.IsNotNull (data, "libRSSupport.so for armeabi-v7a should exist in the apk."); - if (Builder.UseDotNet) { - data = ZipHelper.ReadFileFromZip (zipFile, "lib/x86/libSystem.Native.so"); - Assert.IsNotNull (data, "libSystem.Native.so for x86 should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/armeabi-v7a/libSystem.Native.so"); - Assert.IsNotNull (data, "libSystem.Native.so for armeabi-v7a should exist in the apk."); - } else { - data = ZipHelper.ReadFileFromZip (zipFile, "lib/x86/libmono-native.so"); - Assert.IsNotNull (data, "libmono-native.so for x86 should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/armeabi-v7a/libmono-native.so"); - Assert.IsNotNull (data, "libmono-native.so for armeabi-v7a should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/x86/libMonoPosixHelper.so"); - Assert.IsNotNull (data, "libMonoPosixHelper.so for x86 should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/armeabi-v7a/libMonoPosixHelper.so"); - Assert.IsNotNull (data, "libMonoPosixHelper.so for armeabi-v7a should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/x86/libsqlite3_xamarin.so"); - Assert.IsNotNull (data, "libsqlite3_xamarin.so for x86 should exist in the apk."); - data = ZipHelper.ReadFileFromZip (zipFile, "lib/armeabi-v7a/libsqlite3_xamarin.so"); - Assert.IsNotNull (data, "libsqlite3_xamarin.so for armeabi-v7a should exist in the apk."); - } - } - } - } - } - Directory.Delete (path, recursive: true); - } - - [Test] - public void BuildWithNativeLibraryUnknownAbi () - { - var proj = new XamarinAndroidApplicationProject () { - OtherBuildItems = { - new AndroidItem.AndroidNativeLibrary ("not-a-real-abi\\libtest.so") { - BinaryContent = () => new byte[10], - }, - } - }; - proj.SetAndroidSupportedAbis ("armeabi-v7a", "x86"); - - using (var builder = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) { - builder.ThrowOnBuildFailure = false; - Assert.IsFalse (builder.Build (proj), "Build should have failed."); - Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, $"error XA4301: Cannot determine ABI of native library 'not-a-real-abi{Path.DirectorySeparatorChar}libtest.so'. Move this file to a directory with a valid Android ABI name such as 'libs/armeabi-v7a/'."), - "error about libtest.so should have been raised"); - } - } - - [Test] - public void BuildWithExternalJavaLibrary () - { - var path = Path.Combine ("temp", TestName); - var binding = new XamarinAndroidBindingProject { - ProjectName = "BuildWithExternalJavaLibraryBinding", - AndroidClassParser = "class-parse", - }; - using (var bbuilder = CreateDllBuilder (Path.Combine (path, "BuildWithExternalJavaLibraryBinding"))) { - string multidex_jar = Path.Combine (TestEnvironment.AndroidMSBuildDirectory, "android-support-multidex.jar"); - binding.Jars.Add (new AndroidItem.InputJar (() => multidex_jar)); - - Assert.IsTrue (bbuilder.Build (binding), "Binding build should succeed."); - var proj = new XamarinAndroidApplicationProject { - References = { new BuildItem ("ProjectReference", "..\\BuildWithExternalJavaLibraryBinding\\BuildWithExternalJavaLibraryBinding.csproj"), }, - OtherBuildItems = { new BuildItem ("AndroidExternalJavaLibrary", multidex_jar) }, - Sources = { - new BuildItem ("Compile", "Foo.cs") { - TextContent = () => "public class Foo { public void X () { new Android.Support.Multidex.MultiDexApplication (); } }" - } - }, - }; - using (var builder = CreateApkBuilder (Path.Combine (path, "BuildWithExternalJavaLibrary"))) { - Assert.IsTrue (builder.Build (proj), "App build should succeed"); - } - } - } - [Test] public void CheckItemMetadata ([Values (true, false)] bool isRelease) { @@ -841,52 +787,6 @@ public void BuildApplicationWithSpacesInPath ([Values (true, false)] bool enable } } - [Test] - public void BuildReleaseApplicationWithNugetPackages () - { - var proj = new XamarinAndroidApplicationProject () { - IsRelease = true, - PackageReferences = { - KnownPackages.AndroidSupportV4_27_0_2_1, - }, - }; - using (var b = CreateApkBuilder ()) { - Assert.IsTrue (b.Build (proj), "Build should have succeeded."); - var assets = b.Output.GetIntermediaryAsText (Path.Combine ("..", "project.assets.json")); - StringAssert.Contains ("Xamarin.Android.Support.v4", assets, - "Nuget Package Xamarin.Android.Support.v4.21.0.3.0 should have been restored."); - var src = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "android", "src"); - var main_r_java = Path.Combine (src, proj.PackageNameJavaIntermediatePath, "R.java"); - FileAssert.Exists (main_r_java); - var lib_r_java = Path.Combine (src, "android", "support", "compat", "R.java"); - FileAssert.Exists (lib_r_java); - } - } - - [Test] - public void BuildAfterAddingNuget () - { - var proj = new XamarinAndroidApplicationProject () { - IsRelease = true, - TargetFrameworkVersion = "7.1", - }; - using (var b = CreateApkBuilder ()) { - Assert.IsTrue (b.Build (proj), "first build should have succeeded."); - string build_props = b.Output.GetIntermediaryPath ("build.props"); - FileAssert.Exists (build_props, "build.props should exist after first build."); - proj.PackageReferences.Add (KnownPackages.SupportV7CardView_27_0_2_1); - - Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "second build should have succeeded."); - FileAssert.Exists (build_props, "build.props should exist after second build."); - - proj.MainActivity = proj.DefaultMainActivity.Replace ("clicks", "CLICKS"); - proj.Touch ("MainActivity.cs"); - Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "third build should have succeeded."); - Assert.IsTrue (b.Output.IsTargetSkipped ("_CleanIntermediateIfNeeded"), "A build with no changes to NuGets should *not* trigger `_CleanIntermediateIfNeeded`!"); - FileAssert.Exists (build_props, "build.props should exist after third build."); - } - } - //This test validates the _CleanIntermediateIfNeeded target [Test] [NonParallelizable] @@ -958,151 +858,6 @@ public void BuildInDesignTimeMode ([Values(false, true)] bool useManagedParser) } } - [Test] - public void AndroidLibraryProjectsZipWithOddPaths () - { - var proj = new XamarinAndroidLibraryProject (); - proj.Imports.Add (new Import ("foo.props") { - TextContent = () => $@" - - - $(MSBuildThisFileDirectory)../{TestContext.CurrentContext.Test.Name}/obj/$(Configuration)/foo/ - - " - }); - proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\values\\foo.xml") { - TextContent = () => @"bar", - }); - using (var b = CreateDllBuilder ()) { - Assert.IsTrue (b.Build (proj), "Build should have succeeded."); - - var zipFile = Path.Combine (Root, b.ProjectDirectory, b.Output.OutputPath, $"{proj.ProjectName}.aar"); - FileAssert.Exists (zipFile); - using (var zip = ZipHelper.OpenZip (zipFile)) { - Assert.IsTrue (zip.ContainsEntry ("res/values/foo.xml"), $"{zipFile} should contain a res/values/foo.xml entry"); - } - } - } - -#pragma warning disable 414 - static object [] validateJavaVersionTestCases = new object [] { - new object [] { - /*targetFrameworkVersion*/ "v7.1", - /*buildToolsVersion*/ "24.0.1", - /*JavaVersion*/ "1.8.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v7.1", - /*buildToolsVersion*/ "24.0.1", - /*JavaVersion*/ "1.7.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v7.1", - /*buildToolsVersion*/ "24.0.1", - /*JavaVersion*/ "1.6.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v6.0", - /*buildToolsVersion*/ "24.0.1", - /*JavaVersion*/ "1.8.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v6.0", - /*buildToolsVersion*/ "24.0.0", - /*JavaVersion*/ "1.7.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v6.0", - /*buildToolsVersion*/ "24.0.0", - /*JavaVersion*/ "1.6.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v5.0", - /*buildToolsVersion*/ "24.0.1", - /*JavaVersion*/ "1.8.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v5.0", - /*buildToolsVersion*/ "24.0.0", - /*JavaVersion*/ "1.7.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v5.0", - /*buildToolsVersion*/ "24.0.0", - /*JavaVersion*/ "1.6.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v5.0", - /*buildToolsVersion*/ "24.0.1", - /*JavaVersion*/ "1.6.0_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v7.1", - /*buildToolsVersion*/ "24.0.1", - /*JavaVersion*/ "1.6.x_101", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - new object [] { - /*targetFrameworkVersion*/ "v8.1", - /*buildToolsVersion*/ "24.0.1", - /*JavaVersion*/ "9.0.4", - /*latestSupportedJavaVersion*/ "1.8.0", - /*expectedResult*/ true, - }, - }; -#pragma warning restore 414 - - [Test] - [TestCaseSource (nameof (validateJavaVersionTestCases))] - public void ValidateJavaVersion (string targetFrameworkVersion, string buildToolsVersion, string javaVersion, string latestSupportedJavaVersion, bool expectedResult) - { - var path = Path.Combine ("temp", $"ValidateJavaVersion_{targetFrameworkVersion}_{buildToolsVersion}_{latestSupportedJavaVersion}_{javaVersion}"); - string javaExe = "java"; - string javacExe; - var javaPath = CreateFauxJavaSdkDirectory (Path.Combine (path, "JavaSDK"), javaVersion, out javaExe, out javacExe); - var AndroidSdkDirectory = CreateFauxAndroidSdkDirectory (Path.Combine (path, "android-sdk"), buildToolsVersion); - var proj = new XamarinAndroidApplicationProject () { - IsRelease = true, - TargetFrameworkVersion = targetFrameworkVersion, - UseLatestPlatformSdk = false, - }; - using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), false, false)) { - builder.ThrowOnBuildFailure = false; - builder.Target = "_ResolveSdks"; - Assert.AreEqual (expectedResult, builder.Build (proj, parameters: new string[] { - $"JavaSdkDirectory={javaPath}", - $"JavaToolExe={javaExe}", - $"JavacToolExe={javacExe}", - $"AndroidSdkBuildToolsVersion={buildToolsVersion}", - $"AndroidSdkDirectory={AndroidSdkDirectory}", - $"LatestSupportedJavaVersion={latestSupportedJavaVersion}", - }), string.Format ("Build should have {0}", expectedResult ? "succeeded" : "failed")); - } - Directory.Delete (javaPath, recursive: true); - Directory.Delete (AndroidSdkDirectory, recursive: true); - } - [Test] public void IfAndroidJarDoesNotExistThrowXA5207 () { @@ -1330,47 +1085,6 @@ public void MicrosoftExtensionsHttp () } } - [Test] - public void XA0119 () - { - var proj = new XamarinAndroidApplicationProject (); - proj.SetProperty ("_XASupportsFastDev", "True"); - proj.SetProperty (proj.DebugProperties, "AndroidLinkMode", "Full"); - using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) { - b.Target = "Build"; // SignAndroidPackage would fail for OSS builds - Assert.IsTrue (b.Build (proj), "Build should have succeeded."); - Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, "XA0119"), "Output should contain XA0119 warnings"); - } - } - - [Test] - public void XA0119AAB () - { - var proj = new XamarinAndroidApplicationProject (); - proj.SetProperty ("_XASupportsFastDev", "True"); - proj.SetProperty ("AndroidPackageFormat", "aab"); - using (var builder = CreateApkBuilder ()) { - builder.ThrowOnBuildFailure = false; - Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); - Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, "XA0119"), "Output should contain XA0119 warnings"); - } - } - - [Test] - public void XA0119Interpreter () - { - var proj = new XamarinAndroidApplicationProject { - IsRelease = true, - AotAssemblies = true, - }; - proj.SetProperty ("UseInterpreter", "true"); - using (var builder = CreateApkBuilder ()) { - builder.ThrowOnBuildFailure = false; - Assert.IsTrue (builder.Build (proj), "Build should have succeeded."); - Assert.IsTrue (StringAssertEx.ContainsText (builder.LastBuildOutput, "XA0119"), "Output should contain XA0119 warnings"); - } - } - [Test] public void FastDeploymentDoesNotAddContentProvider () { @@ -1393,94 +1107,6 @@ public void FastDeploymentDoesNotAddContentProvider () } } - [Test] - public void DuplicateJCWNames () - { - var source = @"[Android.Runtime.Register (""examplelib.EmptyClass"")] public class EmptyClass : Java.Lang.Object { }"; - var library1 = new XamarinAndroidLibraryProject () { - ProjectName = "Library1", - Sources = { - new BuildItem.Source ("EmptyClass.cs") { - TextContent = () => source - } - } - }; - var library2 = new XamarinAndroidLibraryProject () { - ProjectName = "Library2", - Sources = { - new BuildItem.Source ("EmptyClass.cs") { - TextContent = () => source - } - } - }; - var app = new XamarinAndroidApplicationProject { - ProjectName = "App1", - References = { - new BuildItem ("ProjectReference", "..\\Library1\\Library1.csproj"), - new BuildItem ("ProjectReference", "..\\Library2\\Library2.csproj") - }, - }; - var projectPath = Path.Combine ("temp", TestName); - using (var lib1b = CreateDllBuilder (Path.Combine (projectPath, library1.ProjectName), cleanupAfterSuccessfulBuild: false)) - using (var lib2b = CreateDllBuilder (Path.Combine (projectPath, library2.ProjectName), cleanupAfterSuccessfulBuild: false)) { - Assert.IsTrue (lib1b.Build (library1), "Build of Library1 should have succeeded"); - Assert.IsTrue (lib2b.Build (library2), "Build of Library2 should have succeeded"); - using (var appb = CreateApkBuilder (Path.Combine (projectPath, app.ProjectName))) { - appb.ThrowOnBuildFailure = false; - Assert.IsFalse (appb.Build (app), "Build of App1 should have failed"); - IEnumerable errors = appb.LastBuildOutput.Where (x => x.Contains ("error XA4215")); - Assert.NotNull (errors, "Error should be XA4215"); - StringAssertEx.Contains ("EmptyClass", errors, "Error should mention the conflicting type name"); - StringAssertEx.Contains ("Library1", errors, "Error should mention all of the assemblies with conflicts"); - StringAssertEx.Contains ("Library2", errors, "Error should mention all of the assemblies with conflicts"); - } - } - } - - [Test] - public void DuplicateManagedNames () - { - var source = @"public class EmptyClass : Java.Lang.Object { }"; - var library1 = new XamarinAndroidLibraryProject () { - ProjectName = "Library1", - Sources = { - new BuildItem.Source ("EmptyClass.cs") { - TextContent = () => source - } - } - }; - var library2 = new XamarinAndroidLibraryProject () { - ProjectName = "Library2", - Sources = { - new BuildItem.Source ("EmptyClass.cs") { - TextContent = () => source - } - } - }; - var app = new XamarinAndroidApplicationProject { - ProjectName = "App1", - References = { - new BuildItem ("ProjectReference", "..\\Library1\\Library1.csproj"), - new BuildItem ("ProjectReference", "..\\Library2\\Library2.csproj") - }, - }; - var projectPath = Path.Combine ("temp", TestName); - using (var lib1b = CreateDllBuilder (Path.Combine (projectPath, library1.ProjectName), cleanupAfterSuccessfulBuild: false)) - using (var lib2b = CreateDllBuilder (Path.Combine (projectPath, library2.ProjectName), cleanupAfterSuccessfulBuild: false)) { - Assert.IsTrue (lib1b.Build (library1), "Build of Library1 should have succeeded"); - Assert.IsTrue (lib2b.Build (library2), "Build of Library2 should have succeeded"); - using (var appb = CreateApkBuilder (Path.Combine (projectPath, app.ProjectName))) { - appb.ThrowOnBuildFailure = false; - Assert.IsTrue (appb.Build (app), "Build of App1 should have succeeded"); - IEnumerable warnings = appb.LastBuildOutput.Where (x => x.Contains ("warning XA4214")); - Assert.NotNull (warnings, "Warning should be XA4214"); - StringAssertEx.Contains ("EmptyClass", warnings, "Warning should mention the conflicting type name"); - StringAssertEx.Contains ("Library1", warnings, "Warning should mention all of the assemblies with conflicts"); - StringAssertEx.Contains ("Library2", warnings, "Warning should mention all of the assemblies with conflicts"); - } - } - } - [Test] public void BuildOutsideVisualStudio () { @@ -1598,114 +1224,6 @@ public void AssemblyWithMissingTargetFramework () } } - [Test] - [Category ("Commercial")] - public void LibraryProjectsShouldSkipGetPrimaryCpuAbi () - { - if (!CommercialBuildAvailable) - Assert.Ignore ("Not required on Open Source Builds"); - const string target = "_GetPrimaryCpuAbi"; - var proj = new XamarinAndroidLibraryProject (); - using (var b = CreateDllBuilder (Path.Combine ("temp", TestName))) { - Assert.IsTrue (b.Build (proj), "Build should have succeeded."); - Assert.IsTrue (b.Output.IsTargetSkipped (target), $"`{target}` should be skipped!"); - } - } - - [Test] - [Category ("Commercial")] - public void LibraryReferenceWithHigherTFVShouldDisplayWarning ([Values (true, false)] bool isRelease) - { - if (!CommercialBuildAvailable || Builder.UseDotNet) - Assert.Ignore ("Not applicable to One .NET or single framework OSS builds."); - - var libproj = new XamarinAndroidLibraryProject () { - IsRelease = isRelease, - ProjectName = "Library1", - }; - var proj = new XamarinAndroidApplicationProject () { - IsRelease = isRelease, - ProjectName = "App1", - UseLatestPlatformSdk = false, - TargetFrameworkVersion = "v9.0", - References = { - new BuildItem ("ProjectReference", $"..\\{libproj.ProjectName}\\{Path.GetFileName (libproj.ProjectFilePath)}") - }, - }; - using (var libBuilder = CreateDllBuilder (Path.Combine ("temp", TestName, libproj.ProjectName))) - using (var appBuilder = CreateApkBuilder (Path.Combine ("temp", TestName, proj.ProjectName))) { - Assert.IsTrue (libBuilder.Build (libproj), "Library build should have succeeded."); - Assert.IsTrue (appBuilder.Build (proj), "App build should have succeeded."); - StringAssertEx.Contains ("warning XA0105", appBuilder.LastBuildOutput, "Build should have produced warning XA0105."); - } - } - - [Test] - public void AllResourcesInClassLibrary ([Values (true, false)] bool useAapt2, [Values (false, true)] bool useDesignerAssembly) - { - if (useDesignerAssembly && !Builder.UseDotNet) { - Assert.Ignore ($"Skipping, {useDesignerAssembly} not supported in Legacy."); - } - AssertAaptSupported (useAapt2); - var path = Path.Combine ("temp", TestName); - - // Create a "library" with all the application stuff in it - var lib = new XamarinAndroidApplicationProject { - ProjectName = "MyLibrary", - Sources = { - new BuildItem.Source ("Bar.cs") { - TextContent = () => "public class Bar { }" - }, - } - }; - lib.SetProperty ("AndroidApplication", "False"); - lib.SetProperty ("AndroidUseDesignerAssembly", useDesignerAssembly.ToString ()); - lib.AndroidUseAapt2 = useAapt2; - if (Builder.UseDotNet) { - lib.RemoveProperty ("OutputType"); - } - - // Create an "app" that is basically empty and references the library - var app = new XamarinAndroidLibraryProject { - ProjectName = "MyApp", - Sources = { - new BuildItem.Source ("Foo.cs") { - TextContent = () => "public class Foo : Bar { }" - }, - }, - OtherBuildItems = { - new BuildItem ("None", "Properties\\AndroidManifest.xml") { - TextContent = () => lib.AndroidManifest, - }, - } - }; - app.SetProperty ("AndroidUseDesignerAssembly", useDesignerAssembly.ToString ()); - app.AndroidResources.Clear (); // No Resources - if (Builder.UseDotNet) { - app.SetProperty (KnownProperties.OutputType, "Exe"); - } else { - app.SetProperty ("AndroidResgenFile", "Resources\\Resource.designer.cs"); - app.SetProperty ("AndroidApplication", "True"); - } - app.AndroidUseAapt2 = useAapt2; - - app.References.Add (new BuildItem.ProjectReference ($"..\\{lib.ProjectName}\\{lib.ProjectName}.csproj", lib.ProjectName, lib.ProjectGuid)); - - using (var libBuilder = CreateDllBuilder (Path.Combine (path, lib.ProjectName))) - using (var appBuilder = CreateApkBuilder (Path.Combine (path, app.ProjectName))) { - Assert.IsTrue (libBuilder.Build (lib), "library build should have succeeded."); - Assert.IsTrue (appBuilder.Build (app), "app build should have succeeded."); - - var r_txt = Path.Combine (Root, appBuilder.ProjectDirectory, app.IntermediateOutputPath, "R.txt"); - FileAssert.Exists (r_txt); - - var resource_designer_cs = GetResourceDesignerPath (appBuilder, app); - FileAssert.Exists (resource_designer_cs); - var contents = GetResourceDesignerText (app, resource_designer_cs); - Assert.AreNotEqual ("", contents); - } - } - [Test] public void WorkManager () { @@ -2094,138 +1612,6 @@ public void CheckLintConfigMerging () } } - [Test] - [NonParallelizable] // fails on NuGet restore - /// - /// Reference https://bugzilla.xamarin.com/show_bug.cgi?id=29568 - /// - public void BuildLibraryWhichUsesResources ([Values (false, true)] bool isRelease) - { - var proj = new XamarinAndroidLibraryProject { IsRelease = isRelease }; - proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat); - proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\values\\Styles.xml") { - TextContent = () => @" - -