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 284fed2c0df..4f6994f5dcc 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 @@ -2067,6 +2067,74 @@ public void BuildAfterAddingNuget () } } + //This test validates the _CleanIntermediateIfNuGetsChange target + [Test] + public void BuildAfterUpgradingNuget ([Values (false, true)] bool usePackageReference) + { + var proj = new XamarinAndroidApplicationProject (); + proj.MainActivity = proj.DefaultMainActivity.Replace ("public class MainActivity : Activity", "public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity"); + + var packages = usePackageReference ? proj.PackageReferences : proj.Packages; + packages.Add (KnownPackages.XamarinForms_2_3_4_231); + packages.Add (KnownPackages.AndroidSupportV4_25_4_0_1); + packages.Add (KnownPackages.SupportCompat_25_4_0_1); + packages.Add (KnownPackages.SupportCoreUI_25_4_0_1); + packages.Add (KnownPackages.SupportCoreUtils_25_4_0_1); + packages.Add (KnownPackages.SupportDesign_25_4_0_1); + packages.Add (KnownPackages.SupportFragment_25_4_0_1); + packages.Add (KnownPackages.SupportMediaCompat_25_4_0_1); + packages.Add (KnownPackages.SupportV7AppCompat_25_4_0_1); + packages.Add (KnownPackages.SupportV7CardView_25_4_0_1); + packages.Add (KnownPackages.SupportV7MediaRouter_25_4_0_1); + + using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) { + if (usePackageReference) { + b.RequiresMSBuild = true; + b.Target = "Restore,Build"; + } + //[TearDown] will still delete if test outcome successful, I need logs if assertions fail but build passes + b.CleanupAfterSuccessfulBuild = + b.CleanupOnDispose = false; + var projectDir = Path.Combine (Root, b.ProjectDirectory); + if (Directory.Exists (projectDir)) + Directory.Delete (projectDir, true); + Assert.IsTrue (b.Build (proj), "first build should have succeeded."); + Assert.IsFalse (b.Output.IsTargetSkipped ("_CleanIntermediateIfNuGetsChange"), "`_CleanIntermediateIfNuGetsChange` should have run!"); + + var nugetStamp = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, proj.ProjectName + ".nuget.stamp"); + FileAssert.Exists (nugetStamp, "`_CleanIntermediateIfNuGetsChange` did not create stamp file!"); + + if (!usePackageReference) { + foreach (var p in proj.Packages) { + foreach (var r in p.References) { + proj.References.Remove (r); + } + } + } + packages.Clear (); + packages.Add (KnownPackages.XamarinForms_3_0_0_561731); + packages.Add (KnownPackages.Android_Arch_Core_Common_26_1_0); + packages.Add (KnownPackages.Android_Arch_Lifecycle_Common_26_1_0); + packages.Add (KnownPackages.Android_Arch_Lifecycle_Runtime_26_1_0); + packages.Add (KnownPackages.AndroidSupportV4_27_0_2_1); + packages.Add (KnownPackages.SupportCompat_27_0_2_1); + packages.Add (KnownPackages.SupportCoreUI_27_0_2_1); + packages.Add (KnownPackages.SupportCoreUtils_27_0_2_1); + packages.Add (KnownPackages.SupportDesign_27_0_2_1); + packages.Add (KnownPackages.SupportFragment_27_0_2_1); + packages.Add (KnownPackages.SupportMediaCompat_27_0_2_1); + packages.Add (KnownPackages.SupportV7AppCompat_27_0_2_1); + packages.Add (KnownPackages.SupportV7CardView_27_0_2_1); + packages.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1); + packages.Add (KnownPackages.SupportV7RecyclerView_27_0_2_1); + b.Save (proj, doNotCleanupOnUpdate: true); + Assert.IsTrue (b.Build (proj), "second build should have succeeded."); + Assert.IsFalse (b.Output.IsTargetSkipped ("_CleanIntermediateIfNuGetsChange"), "`_CleanIntermediateIfNuGetsChange` should have run!"); + FileAssert.Exists (nugetStamp, "`_CleanIntermediateIfNuGetsChange` did not create stamp file!"); + Assert.IsFalse (StringAssertEx.ContainsText (b.LastBuildOutput, "Xamarin.Android.Support.v4.dll: extracted files are up to date"), "`ResolveLibraryProjectImports` should not skip `Xamarin.Android.Support.v4.dll`!"); + } + } + [Test] public void CheckTargetFrameworkVersion () { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs index 97eae7708dc..593d90a1f76 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownPackages.cs @@ -49,6 +49,15 @@ public static class KnownPackages MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v4.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.v4.dll" } } }; + public static Package AndroidSupportV4_27_0_2_1 = new Package () { + Id = "Xamarin.Android.Support.v4", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.v4") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v4.27.0.2.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.v4.dll" } + } + }; public static Package AndroidSupportV4Beta = new Package () { Id = "Xamarin.Android.Support.v4", Version = "21.0.0.0-beta1", @@ -103,6 +112,16 @@ public static class KnownPackages MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.RecyclerView.21.0.0.0-beta1\\lib\\MonoAndroid\\Xamarin.Android.Support.v7.RecyclerView.dll" } } }; + public static Package SupportV7RecyclerView_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.v7.RecyclerView", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.V7.RecyclerView") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.RecyclerView.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.v7.RecyclerView.dll" + } + } + }; public static Package SupportV7CardView = new Package { Id = "Xamarin.Android.Support.v7.Cardview", Version = "21.0.3.0", @@ -130,6 +149,15 @@ public static class KnownPackages MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.CardView.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.v7.CardView.dll" } } }; + public static Package SupportV7CardView_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.v7.Cardview", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.v7.CardView") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.CardView.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.v7.CardView.dll" } + } + }; public static Package SupportV7AppCompat_21_0_3_0 = new Package { Id = "Xamarin.Android.Support.v7.AppCompat", Version = "21.0.3.0", @@ -211,6 +239,60 @@ public static class KnownPackages MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Media.Compat.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.Media.Compat.dll" } } }; + public static Package SupportV7AppCompat_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.v7.AppCompat", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.v7.AppCompat") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.AppCompat.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.v7.AppCompat.dll" } + } + }; + public static Package SupportCompat_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.Compat", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.Compat") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Compat.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.Compat.dll" } + } + }; + public static Package SupportCoreUI_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.Core.UI", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.Core.UI") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Core.UI.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.Core.UI.dll" } + } + }; + public static Package SupportCoreUtils_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.Core.Utils", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.Core.Utils") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Core.Utils.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.Core.Utils.dll" } + } + }; + public static Package SupportFragment_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.Fragment", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.Fragment") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Fragment.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.Fragment.dll" } + } + }; + public static Package SupportMediaCompat_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.Media.Compat", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.Media.Compat") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Media.Compat.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.Media.Compat.dll" } + } + }; public static Package SupportV7MediaRouter_21_0_3_0 = new Package { Id = "Xamarin.Android.Support.v7.MediaRouter", Version = "21.0.3.0", @@ -220,6 +302,24 @@ public static class KnownPackages MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.MediaRouter.21.0.3.0\\lib\\MonoAndroid403\\Xamarin.Android.Support.v7.MediaRouter.dll" } } }; + public static Package SupportV7MediaRouter_25_4_0_1 = new Package { + Id = "Xamarin.Android.Support.v7.MediaRouter", + Version = "25.4.0.1", + TargetFramework = "MonoAndroid70", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.v7.MediaRouter") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.MediaRouter.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.v7.MediaRouter.dll" } + } + }; + public static Package SupportV7MediaRouter_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.v7.MediaRouter", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.v7.MediaRouter") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.v7.MediaRouter.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.v7.MediaRouter.dll" } + } + }; public static Package SupportV7Palette_22_1_1_1 = new Package { Id = "Xamarin.Android.Support.v7.Palette", Version = "22.1.1.1", @@ -238,6 +338,15 @@ public static class KnownPackages MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Design.25.4.0.1\\lib\\MonoAndroid70\\Xamarin.Android.Support.Design.dll" } } }; + public static Package SupportDesign_27_0_2_1 = new Package { + Id = "Xamarin.Android.Support.Design", + Version = "27.0.2.1", + TargetFramework = "MonoAndroid81", + References = { + new BuildItem.Reference ("Xamarin.Android.Support.Design") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Support.Design.27.0.2.1\\lib\\MonoAndroid81\\Xamarin.Android.Support.Design.dll" } + } + }; public static Package GooglePlayServices_22_0_0_2 = new Package { Id = "Xamarin.GooglePlayServices", Version = "22.0.0.2", @@ -318,6 +427,28 @@ public static class KnownPackages }, } }; + public static Package XamarinForms_3_0_0_561731 = new Package { + Id = "Xamarin.Forms", + Version = "3.0.0.561731", + TargetFramework = "MonoAndroid10", + References = { + new BuildItem.Reference ("Xamarin.Forms.Platform.Android") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.3.0.0.561731\\lib\\MonoAndroid10\\Xamarin.Forms.Platform.Android.dll" + }, + new BuildItem.Reference ("FormsViewGroup") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.3.0.0.561731\\lib\\MonoAndroid10\\FormsViewGroup.dll" + }, + new BuildItem.Reference ("Xamarin.Forms.Core") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.3.0.0.561731\\lib\\MonoAndroid10\\Xamarin.Forms.Core.dll" + }, + new BuildItem.Reference ("Xamarin.Forms.Xaml") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.3.0.0.561731\\lib\\MonoAndroid10\\Xamarin.Forms.Xaml.dll" + }, + new BuildItem.Reference ("Xamarin.Forms.Platform") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Forms.3.0.0.561731\\lib\\MonoAndroid10\\Xamarin.Forms.Platform.dll" + }, + } + }; public static Package CocosSharp_PCL_Shared_1_5_0_0 = new Package { Id = "CocosSharp.PCL.Shared", Version = "1.5.0.0", @@ -405,6 +536,36 @@ public static class KnownPackages } } }; + public static Package Android_Arch_Core_Common_26_1_0 = new Package { + Id = "Xamarin.Android.Arch.Core.Common", + Version = "26.1.0", + TargetFramework = "MonoAndroid80", + References = { + new BuildItem.Reference("Xamarin.Android.Arch.Core.Common") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Arch.Core.Common.26.1.0\\lib\\MonoAndroid80\\Xamarin.Android.Arch.Core.Common.dll" + } + } + }; + public static Package Android_Arch_Lifecycle_Common_26_1_0 = new Package { + Id = "Xamarin.Android.Arch.Lifecycle.Common", + Version = "26.1.0", + TargetFramework = "MonoAndroid80", + References = { + new BuildItem.Reference("Xamarin.Android.Arch.Lifecycle.Common") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Arch.Lifecycle.Common.26.1.0\\lib\\MonoAndroid80\\Xamarin.Android.Arch.Lifecycle.Common.dll" + } + } + }; + public static Package Android_Arch_Lifecycle_Runtime_26_1_0 = new Package { + Id = "Xamarin.Android.Arch.Lifecycle.Runtime", + Version = "26.1.0", + TargetFramework = "MonoAndroid80", + References = { + new BuildItem.Reference("Xamarin.Android.Arch.Lifecycle.Runtime") { + MetadataValues = "HintPath=..\\packages\\Xamarin.Android.Arch.Lifecycle.Runtime.26.1.0\\lib\\MonoAndroid80\\Xamarin.Android.Arch.Lifecycle.Runtime.dll" + } + } + }; } } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 8770b205e1e..8754de4cb1c 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -271,6 +271,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. <_AndroidLibrayProjectAssemblyMapFile>$(_AndroidLibrayProjectIntermediatePath)map.cache <_AndroidProguardInputJarFilter>(!META-INF/MANIFEST.MF) <_AndroidAapt2VersionFile>$(IntermediateOutputPath)aapt2.version + <_AndroidNuGetStampFile>$(IntermediateOutputPath)$(MSBuildProjectName).nuget.stamp $(EnableProguard) @@ -524,6 +525,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. _CheckTargetFramework; _RemoveLegacyDesigner; _ValidateAndroidPackageProperties; + _CleanIntermediateIfNuGetsChange; $(BuildDependsOn); _CompileDex; $(_PostBuildTargets) @@ -542,6 +544,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. _CheckTargetFramework; _RemoveLegacyDesigner; _ValidateAndroidPackageProperties; + _CleanIntermediateIfNuGetsChange; $(BuildDependsOn); @@ -643,6 +646,23 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. + + + <_NuGetAssetsFile Condition="Exists('$(ProjectLockFile)')">$(ProjectLockFile) + <_NuGetAssetsFile Condition="'$(_NuGetAssetsFile)' == '' and Exists('packages.config')">packages.config + + + + + + + + + + +