public void XamarinLegacySdk() { var proj = new XASdkProject(outputType: "Library") { Sdk = "Xamarin.Legacy.Sdk/0.1.0-alpha2", Sources = { new AndroidItem.AndroidLibrary("javaclasses.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestJar, } } }; using var b = new Builder(); var dotnetTargetFramework = "net6.0-android30.0"; var legacyTargetFrameworkVersion = b.LatestTargetFrameworkVersion().TrimStart('v'); var legacyTargetFramework = $"monoandroid{legacyTargetFrameworkVersion}"; proj.SetProperty("TargetFramework", value: ""); proj.SetProperty("TargetFrameworks", value: $"{dotnetTargetFramework};{legacyTargetFramework}"); var dotnet = CreateDotNetBuilder(proj); Assert.IsTrue(dotnet.Pack(), "`dotnet pack` should succeed"); var nupkgPath = Path.Combine(FullProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.1.0.0.nupkg"); FileAssert.Exists(nupkgPath); using var nupkg = ZipHelper.OpenZip(nupkgPath); nupkg.AssertContainsEntry(nupkgPath, $"lib/{dotnetTargetFramework}/{proj.ProjectName}.dll"); nupkg.AssertContainsEntry(nupkgPath, $"lib/{legacyTargetFramework}/{proj.ProjectName}.dll"); }
public void DotNetPublish([Values(false, true)] bool isRelease) { const string runtimeIdentifier = "android.21-arm"; var proj = new XASdkProject { IsRelease = isRelease }; proj.SetProperty(KnownProperties.RuntimeIdentifier, runtimeIdentifier); var dotnet = CreateDotNetBuilder(proj); Assert.IsTrue(dotnet.Publish(), "first `dotnet publish` should succeed"); var publishDirectory = Path.Combine(FullProjectDirectory, proj.OutputPath, runtimeIdentifier, "publish"); var apk = Path.Combine(publishDirectory, $"{proj.PackageName}.apk"); var apkSigned = Path.Combine(publishDirectory, $"{proj.PackageName}-Signed.apk"); FileAssert.Exists(apk); FileAssert.Exists(apkSigned); Assert.IsTrue(dotnet.Publish(parameters: new [] { "AndroidPackageFormat=aab" }), $"second `dotnet publish` should succeed"); var aab = Path.Combine(publishDirectory, $"{proj.PackageName}.aab"); var aabSigned = Path.Combine(publishDirectory, $"{proj.PackageName}-Signed.aab"); FileAssert.DoesNotExist(apk); FileAssert.DoesNotExist(apkSigned); FileAssert.Exists(aab); FileAssert.Exists(aabSigned); }
public void DotNetPublish([Values(false, true)] bool isRelease) { var proj = new XASdkProject(SdkVersion) { IsRelease = isRelease }; proj.SetProperty(KnownProperties.AndroidLinkMode, AndroidLinkMode.None.ToString()); var dotnet = CreateDotNetBuilder(proj); Assert.IsTrue(dotnet.Publish(), "`dotnet publish` should succeed"); }
public void DotNetBuild(string runtimeIdentifier, bool isRelease) { var abi = MonoAndroidHelper.RuntimeIdentifierToAbi(runtimeIdentifier); var proj = new XASdkProject { IsRelease = isRelease }; proj.OtherBuildItems.Add(new AndroidItem.InputJar("javaclasses.jar") { BinaryContent = () => Convert.FromBase64String(InlineData.JavaClassesJarBase64) }); // TODO: bring back when Xamarin.Android.Bindings.Documentation.targets is working //proj.OtherBuildItems.Add (new BuildItem ("JavaSourceJar", "javasources.jar") { // BinaryContent = () => Convert.FromBase64String (InlineData.JavaSourcesJarBase64) //}); proj.SetProperty(KnownProperties.RuntimeIdentifier, runtimeIdentifier); var dotnet = CreateDotNetBuilder(proj); Assert.IsTrue(dotnet.Build(), "`dotnet build` should succeed"); // TODO: run for release once illink warnings are gone // context: https://github.com/xamarin/xamarin-android/issues/4708 if (!isRelease) { Assert.IsTrue(StringAssertEx.ContainsText(dotnet.LastBuildOutput, " 0 Warning(s)"), "Should have no MSBuild warnings."); } var outputPath = Path.Combine(Root, dotnet.ProjectDirectory, proj.OutputPath, runtimeIdentifier); var assemblyPath = Path.Combine(outputPath, "UnnamedProject.dll"); FileAssert.Exists(assemblyPath); using (var assembly = AssemblyDefinition.ReadAssembly(assemblyPath)) { var typeName = "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceJarTest"; var type = assembly.MainModule.GetType(typeName); Assert.IsNotNull(type, $"{assemblyPath} should contain {typeName}"); } var apk = Path.Combine(outputPath, "UnnamedProject.UnnamedProject.apk"); FileAssert.Exists(apk); using (var zip = ZipHelper.OpenZip(apk)) { Assert.IsTrue(zip.ContainsEntry($"lib/{abi}/libmonodroid.so"), "libmonodroid.so should exist."); Assert.IsTrue(zip.ContainsEntry($"lib/{abi}/libmonosgen-2.0.so"), "libmonosgen-2.0.so should exist."); } }
public void DotNetBuild(string runtimeIdentifiers, bool isRelease) { var proj = new XASdkProject { IsRelease = isRelease }; proj.OtherBuildItems.Add(new AndroidItem.InputJar("javaclasses.jar") { BinaryContent = () => Convert.FromBase64String(InlineData.JavaClassesJarBase64) }); // TODO: bring back when Xamarin.Android.Bindings.Documentation.targets is working //proj.OtherBuildItems.Add (new BuildItem ("JavaSourceJar", "javasources.jar") { // BinaryContent = () => Convert.FromBase64String (InlineData.JavaSourcesJarBase64) //}); if (!runtimeIdentifiers.Contains(";")) { proj.SetProperty(KnownProperties.RuntimeIdentifier, runtimeIdentifiers); } else { proj.SetProperty(KnownProperties.RuntimeIdentifiers, runtimeIdentifiers); } var dotnet = CreateDotNetBuilder(proj); Assert.IsTrue(dotnet.Build(), "`dotnet build` should succeed"); // TODO: run for release once illink warnings are gone // context: https://github.com/xamarin/xamarin-android/issues/4708 if (!isRelease) { Assert.IsTrue(StringAssertEx.ContainsText(dotnet.LastBuildOutput, " 0 Warning(s)"), "Should have no MSBuild warnings."); } var outputPath = Path.Combine(FullProjectDirectory, proj.OutputPath); if (!runtimeIdentifiers.Contains(";")) { outputPath = Path.Combine(outputPath, runtimeIdentifiers); } var files = Directory.EnumerateFileSystemEntries(outputPath) .Select(Path.GetFileName) .OrderBy(f => f) .ToArray(); CollectionAssert.AreEqual(new [] { $"{proj.ProjectName}.dll", $"{proj.ProjectName}.pdb", $"{proj.PackageName}.apk", $"{proj.PackageName}-Signed.apk", }, 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"; var type = assembly.MainModule.GetType(typeName); Assert.IsNotNull(type, $"{assemblyPath} should contain {typeName}"); } bool expectEmbeddedAssembies = !(CommercialBuildAvailable && !isRelease); var apkPath = Path.Combine(outputPath, "UnnamedProject.UnnamedProject.apk"); FileAssert.Exists(apkPath); using (var apk = ZipHelper.OpenZip(apkPath)) { apk.AssertContainsEntry(apkPath, $"assemblies/{proj.ProjectName}.dll", shouldContainEntry: expectEmbeddedAssembies); apk.AssertContainsEntry(apkPath, $"assemblies/{proj.ProjectName}.pdb", shouldContainEntry: !CommercialBuildAvailable && !isRelease); apk.AssertContainsEntry(apkPath, $"assemblies/System.Linq.dll", shouldContainEntry: expectEmbeddedAssembies); var rids = runtimeIdentifiers.Split(';'); foreach (var abi in rids.Select(MonoAndroidHelper.RuntimeIdentifierToAbi)) { apk.AssertContainsEntry(apkPath, $"lib/{abi}/libmonodroid.so"); apk.AssertContainsEntry(apkPath, $"lib/{abi}/libmonosgen-2.0.so"); if (rids.Length > 1) { apk.AssertContainsEntry(apkPath, $"assemblies/{abi}/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies); apk.AssertContainsEntry(apkPath, $"assemblies/{abi}/System.Collections.Concurrent.dll", shouldContainEntry: expectEmbeddedAssembies); } else { apk.AssertContainsEntry(apkPath, "assemblies/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies); apk.AssertContainsEntry(apkPath, "assemblies/System.Collections.Concurrent.dll", shouldContainEntry: expectEmbeddedAssembies); } } } }
public void DotNetBuild(string runtimeIdentifiers, bool isRelease) { var proj = new XASdkProject { IsRelease = isRelease }; proj.OtherBuildItems.Add(new AndroidItem.InputJar("javaclasses.jar") { BinaryContent = () => Convert.FromBase64String(InlineData.JavaClassesJarBase64) }); // TODO: bring back when Xamarin.Android.Bindings.Documentation.targets is working //proj.OtherBuildItems.Add (new BuildItem ("JavaSourceJar", "javasources.jar") { // BinaryContent = () => Convert.FromBase64String (InlineData.JavaSourcesJarBase64) //}); if (!runtimeIdentifiers.Contains(";")) { proj.SetProperty(KnownProperties.RuntimeIdentifier, runtimeIdentifiers); } else { proj.SetProperty(KnownProperties.RuntimeIdentifiers, runtimeIdentifiers); } var dotnet = CreateDotNetBuilder(proj); Assert.IsTrue(dotnet.Build(), "`dotnet build` should succeed"); // TODO: run for release once illink warnings are gone // context: https://github.com/xamarin/xamarin-android/issues/4708 if (!isRelease) { Assert.IsTrue(StringAssertEx.ContainsText(dotnet.LastBuildOutput, " 0 Warning(s)"), "Should have no MSBuild warnings."); } var outputPath = Path.Combine(FullProjectDirectory, proj.OutputPath); if (!runtimeIdentifiers.Contains(";")) { outputPath = Path.Combine(outputPath, runtimeIdentifiers); } // TODO: With workloads we don't control the import of Microsoft.NET.Sdk/Sdk.targets. // We can no longer change the default values of `$(GenerateDependencyFile)` and `$(ProduceReferenceAssembly)` as a result. // We should update Microsoft.NET.Sdk to default both of these properties to false when the `$(TargetPlatformIdentifier)` is "mobile" (Android, iOS, etc). // Alternatively, the workload concept could be updated to support some sort of `Before.Microsoft.NET.targets` hook. /* var files = Directory.EnumerateFileSystemEntries (outputPath) * .Select (Path.GetFileName) * .OrderBy (f => f); * CollectionAssert.AreEqual (new [] { * $"{proj.ProjectName}.dll", * $"{proj.ProjectName}.pdb", * $"{proj.PackageName}.apk", * $"{proj.PackageName}-Signed.apk", * }, 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"; var type = assembly.MainModule.GetType(typeName); Assert.IsNotNull(type, $"{assemblyPath} should contain {typeName}"); } bool expectEmbeddedAssembies = !(CommercialBuildAvailable && !isRelease); var apkPath = Path.Combine(outputPath, "UnnamedProject.UnnamedProject.apk"); FileAssert.Exists(apkPath); using (var apk = ZipHelper.OpenZip(apkPath)) { var rids = runtimeIdentifiers.Split(';'); foreach (var abi in rids.Select(MonoAndroidHelper.RuntimeIdentifierToAbi)) { apk.AssertContainsEntry(apkPath, $"lib/{abi}/libmonodroid.so"); apk.AssertContainsEntry(apkPath, $"lib/{abi}/libmonosgen-2.0.so"); if (rids.Length > 1) { apk.AssertContainsEntry(apkPath, $"assemblies/{abi}/System.Private.CoreLib.dll", expectEmbeddedAssembies); } else { apk.AssertContainsEntry(apkPath, "assemblies/System.Private.CoreLib.dll", expectEmbeddedAssembies); } } } }
public void DotNetBuild(string runtimeIdentifiers, bool isRelease) { var proj = new XASdkProject { IsRelease = isRelease, ExtraNuGetConfigSources = { "https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json" }, PackageReferences = { new Package { Id = "Xamarin.AndroidX.AppCompat", Version = "1.2.0.7-net6preview01" }, new Package { Id = "Microsoft.AspNetCore.Components.WebView", Version = "6.0.0-preview.5.21301.17" }, new Package { Id = "Microsoft.Extensions.FileProviders.Embedded", Version = "6.0.0-preview.6.21306.3" }, new Package { Id = "Microsoft.JSInterop", Version = "6.0.0-preview.6.21306.3" }, new Package { Id = "System.Text.Json", Version = "6.0.0-preview.7.21323.3" }, }, Sources = { new BuildItem("EmbeddedResource", "Foo.resx") { TextContent = () => InlineData.ResxWithContents("<data name=\"CancelButton\"><value>Cancel</value></data>") }, new BuildItem("EmbeddedResource", "Foo.es.resx") { TextContent = () => InlineData.ResxWithContents("<data name=\"CancelButton\"><value>Cancelar</value></data>") }, } }; proj.MainActivity = proj.DefaultMainActivity.Replace(": Activity", ": AndroidX.AppCompat.App.AppCompatActivity"); proj.OtherBuildItems.Add(new AndroidItem.InputJar("javaclasses.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestJar, }); proj.OtherBuildItems.Add(new BuildItem("JavaSourceJar", "javaclasses-sources.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestSourcesJar, }); if (!runtimeIdentifiers.Contains(";")) { proj.SetProperty(KnownProperties.RuntimeIdentifier, runtimeIdentifiers); } else { proj.SetProperty(KnownProperties.RuntimeIdentifiers, runtimeIdentifiers); } var dotnet = CreateDotNetBuilder(proj); Assert.IsTrue(dotnet.Build(), "`dotnet build` should succeed"); dotnet.AssertHasNoWarnings(); var outputPath = Path.Combine(FullProjectDirectory, proj.OutputPath); var intermediateOutputPath = Path.Combine(FullProjectDirectory, 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) .ToArray(); var expectedFiles = new[] { $"{proj.PackageName}.apk", $"{proj.PackageName}-Signed.apk", "es", $"{proj.ProjectName}.dll", $"{proj.ProjectName}.pdb", $"{proj.ProjectName}.runtimeconfig.json", $"{proj.ProjectName}.xml", }; CollectionAssert.AreEqual(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"; var type = assembly.MainModule.GetType(typeName); Assert.IsNotNull(type, $"{assemblyPath} should contain {typeName}"); } var rids = runtimeIdentifiers.Split(';'); if (isRelease) { // Check for stripped native libraries foreach (var rid in rids) { FileAssert.Exists(Path.Combine(intermediateOutputPath, "native", rid, "libmono-android.release.so")); FileAssert.Exists(Path.Combine(intermediateOutputPath, "native", rid, "libmonosgen-2.0.so")); } } bool expectEmbeddedAssembies = !(CommercialBuildAvailable && !isRelease); var apkPath = Path.Combine(outputPath, $"{proj.PackageName}.apk"); FileAssert.Exists(apkPath); using (var apk = ZipHelper.OpenZip(apkPath)) { apk.AssertContainsEntry(apkPath, $"assemblies/{proj.ProjectName}.dll", shouldContainEntry: expectEmbeddedAssembies); apk.AssertContainsEntry(apkPath, $"assemblies/{proj.ProjectName}.pdb", shouldContainEntry: !CommercialBuildAvailable && !isRelease); apk.AssertContainsEntry(apkPath, $"assemblies/System.Linq.dll", shouldContainEntry: expectEmbeddedAssembies); apk.AssertContainsEntry(apkPath, $"assemblies/es/{proj.ProjectName}.resources.dll", shouldContainEntry: expectEmbeddedAssembies); foreach (var abi in rids.Select(AndroidRidAbiHelper.RuntimeIdentifierToAbi)) { apk.AssertContainsEntry(apkPath, $"lib/{abi}/libmonodroid.so"); apk.AssertContainsEntry(apkPath, $"lib/{abi}/libmonosgen-2.0.so"); if (rids.Length > 1) { apk.AssertContainsEntry(apkPath, $"assemblies/{abi}/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies); } else { apk.AssertContainsEntry(apkPath, "assemblies/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies); } } } }
public void DotNetBuild(string runtimeIdentifiers, bool isRelease) { var proj = new XASdkProject { IsRelease = isRelease, Sources = { new BuildItem("EmbeddedResource", "Foo.resx") { TextContent = () => InlineData.ResxWithContents("<data name=\"CancelButton\"><value>Cancel</value></data>") }, new BuildItem("EmbeddedResource", "Foo.es.resx") { TextContent = () => InlineData.ResxWithContents("<data name=\"CancelButton\"><value>Cancelar</value></data>") }, } }; proj.OtherBuildItems.Add(new AndroidItem.InputJar("javaclasses.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestJar, }); proj.OtherBuildItems.Add(new BuildItem("JavaSourceJar", "javaclasses-sources.jar") { BinaryContent = () => ResourceData.JavaSourceJarTestSourcesJar, }); if (!runtimeIdentifiers.Contains(";")) { proj.SetProperty(KnownProperties.RuntimeIdentifier, runtimeIdentifiers); } else { proj.SetProperty(KnownProperties.RuntimeIdentifiers, runtimeIdentifiers); } var dotnet = CreateDotNetBuilder(proj); Assert.IsTrue(dotnet.Build(), "`dotnet build` should succeed"); // TODO: run for release once illink warnings are gone // context: https://github.com/xamarin/xamarin-android/issues/4708 if (!isRelease) { Assert.IsTrue(StringAssertEx.ContainsText(dotnet.LastBuildOutput, " 0 Warning(s)"), "Should have no MSBuild warnings."); } var outputPath = Path.Combine(FullProjectDirectory, proj.OutputPath); if (!runtimeIdentifiers.Contains(";")) { outputPath = Path.Combine(outputPath, runtimeIdentifiers); } var files = Directory.EnumerateFileSystemEntries(outputPath) .Select(Path.GetFileName) .OrderBy(f => f) .ToArray(); var expectedFiles = new[] { "es", $"{proj.ProjectName}.dll", $"{proj.ProjectName}.pdb", $"{proj.PackageName}.apk", $"{proj.PackageName}-Signed.apk", $"{proj.ProjectName}.xml", }; CollectionAssert.AreEqual(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"; var type = assembly.MainModule.GetType(typeName); Assert.IsNotNull(type, $"{assemblyPath} should contain {typeName}"); } bool expectEmbeddedAssembies = !(CommercialBuildAvailable && !isRelease); var apkPath = Path.Combine(outputPath, "UnnamedProject.UnnamedProject.apk"); FileAssert.Exists(apkPath); using (var apk = ZipHelper.OpenZip(apkPath)) { apk.AssertContainsEntry(apkPath, $"assemblies/{proj.ProjectName}.dll", shouldContainEntry: expectEmbeddedAssembies); apk.AssertContainsEntry(apkPath, $"assemblies/{proj.ProjectName}.pdb", shouldContainEntry: !CommercialBuildAvailable && !isRelease); apk.AssertContainsEntry(apkPath, $"assemblies/System.Linq.dll", shouldContainEntry: expectEmbeddedAssembies); apk.AssertContainsEntry(apkPath, $"assemblies/es/{proj.ProjectName}.resources.dll", shouldContainEntry: expectEmbeddedAssembies); var rids = runtimeIdentifiers.Split(';'); foreach (var abi in rids.Select(AndroidRidAbiHelper.RuntimeIdentifierToAbi)) { apk.AssertContainsEntry(apkPath, $"lib/{abi}/libmonodroid.so"); apk.AssertContainsEntry(apkPath, $"lib/{abi}/libmonosgen-2.0.so"); if (rids.Length > 1) { apk.AssertContainsEntry(apkPath, $"assemblies/{abi}/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies); } else { apk.AssertContainsEntry(apkPath, "assemblies/System.Private.CoreLib.dll", shouldContainEntry: expectEmbeddedAssembies); } } } }