From 7c4284d7179a06d758eb2da6acf79fbcccc486ad Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 29 Oct 2019 16:14:03 -0500 Subject: [PATCH] [Xamarin.Android.Build.Tasks] remove the code that XA0121 deprecated Context: https://github.com/xamarin/xamarin-android/pull/3654 Context: https://docs.microsoft.com/en-us/xamarin/android/release-notes/10/10.1#xa0121-deprecation-warning-for-old-xamarinandroidsupport-library-versions In VS 16.4 / Xamarin.Android 10.1, we deprecated ``. This PR removes the behavior completely for 16.5, since it uses SHA1. We aim to remove all SHA1 and MD5 usage for 16.5. NuGet packages I've seen that no longer work: * Android Support Libraries, 25.x and older * Google Play Services older than 44.x I have still been able to use an old Xamarin.Forms (2.3.4) in combination with newer support libraries. ~~ XA0121 is now an error ~~ We give a build error now in `` if we encounter the unsupported attributes. This target runs very early in the build, so we have to do it at this point. ~~ JcwGen-Tests ~~ These tests were using these attributes such as: [assembly: Android.IncludeAndroidResourcesFromAttribute ("./", SourceUrl="file:///JavaLib.zip")] [assembly: Java.Interop.JavaLibraryReference ("classes.jar", SourceUrl="file:///JavaLib.zip")] [assembly: Android.NativeLibraryReference ("arm64-v8a/libsimple.so", SourceUrl="file:///NativeLib.zip", Version="native-lib-1")] Instead, I switched to use `@(LibraryProjectZip)` for the `.aar` file and `@(EmbeddedNativeLibrary)` for the `.so` files. ~~ Designer Tests ~~ The designer tests build the MyDriving app: https://github.com/Azure-Samples/MyDriving Which uses old NuGet packages that now fail, and is now in read-only mode on Github. I suspect we may just need to remove that test? error XA0121: Assembly 'Xamarin.Android.Support.CustomTabs' is using '[assembly: Java.Interop.JavaLibraryReferenceAttribute]', which is no longer supported. Use a newer version of this NuGet package or notify the library author. --- Documentation/guides/messages/xa0121.md | 19 +- .../IncludeAndroidResourcesFromAttribute.cs | 2 +- .../NativeLibraryReferenceAttribute.cs | 2 +- .../Android/ReferenceFilesAttribute.cs | 2 +- .../JavaLibraryReferenceAttribute.cs | 2 +- .../Android/Xamarin.Android.Aapt.targets | 2 - .../Android/Xamarin.Android.Aapt2.targets | 2 +- .../Android/Xamarin.Android.Designer.targets | 9 - .../Tasks/FilterAssemblies.cs | 36 +- .../GetAdditionalResourcesFromAssemblies.cs | 482 ------------------ ...eadAdditionalResourcesFromAssemblyCache.cs | 64 --- .../Tasks/ResolveLibraryProjectImports.cs | 4 +- .../AndroidUpdateResourcesTest.cs | 86 +--- .../BindingBuildTest.cs | 19 +- .../Xamarin.Android.Build.Tests/BuildTest.cs | 155 ++---- .../DesignerTests.cs | 37 +- .../IncrementalBuildTest.cs | 1 - .../ManifestTest.cs | 14 +- .../PackagingTest.cs | 47 +- .../SupportV7RecyclerViewTest.cs | 27 - ...tAdditionalResourcesFromAssembliesTests.cs | 27 - .../Utilities/BaseTest.cs | 34 -- .../Xamarin.Android.Build.Tests/WearTests.cs | 1 - ...marin.Android.Build.Tests.Shared.projitems | 1 - .../Xamarin.Android.Build.Tests.csproj | 1 - .../Android/KnownPackages.cs | 316 +----------- .../Xamarin.ProjectTools/Android/Versions.cs | 8 + .../Android/XamarinAndroidProject.cs | 2 +- .../XamarinAndroidWearApplicationProject.cs | 2 +- .../Utilities/MetadataExtensions.cs | 27 - .../Xamarin.Android.Bindings.targets | 31 -- .../Xamarin.Android.Build.Tasks.csproj | 2 - .../Xamarin.Android.Common.targets | 113 +--- .../Properties/AssemblyInfo.cs | 29 -- ...ndroid.LibraryProjectZip-LibBinding.csproj | 5 +- ...droid.LibraryProjectZip-LibBinding.targets | 43 +- .../Tests/InstantRunTest.cs | 8 +- 37 files changed, 229 insertions(+), 1433 deletions(-) delete mode 100644 src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs delete mode 100644 src/Xamarin.Android.Build.Tasks/Tasks/ReadAdditionalResourcesFromAssemblyCache.cs delete mode 100644 src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/SupportV7RecyclerViewTest.cs delete mode 100644 src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/GetAdditionalResourcesFromAssembliesTests.cs diff --git a/Documentation/guides/messages/xa0121.md b/Documentation/guides/messages/xa0121.md index c736263a2f1..728e4cdfb49 100644 --- a/Documentation/guides/messages/xa0121.md +++ b/Documentation/guides/messages/xa0121.md @@ -1,21 +1,21 @@ --- -title: Xamarin.Android warning XA0121 -description: XA0121 warning code -ms.date: 09/19/2019 +title: Xamarin.Android error XA0121 +description: XA0121 error code +ms.date: 10/30/2019 --- -# Xamarin.Android warning XA0121 +# Xamarin.Android error XA0121 ## Issue The behavior implemented in the -`` MSBuild task is now -deprecated. +`` MSBuild task is no longer +supported. This MSBuild task is a precursor to [Xamarin.Build.Download][xbd] that enables downloading of Android packages from the internet. Libraries using any of the following custom assembly-level attributes -will encounter this warning: +will encounter this error: * `IncludeAndroidResourcesFromAttribute` * `NativeLibraryReferenceAttribute` @@ -26,9 +26,8 @@ will encounter this warning: The [Xamarin Support Libraries][supportlibs], can be simply updated to a newer version on NuGet. -Library authors will need to remove usage of these deprecated -attributes. Their functionality will be removed in a future version of -Xamarin.Android. +Library authors will need to remove usage of these attributes. Their +functionality was removed in Xamarin.Android 10.2. [xbd]: https://www.nuget.org/packages/Xamarin.Build.Download [supportlibs]: https://github.com/xamarin/AndroidSupportComponents diff --git a/src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs b/src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs index e89125dfd86..5430424083f 100644 --- a/src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs +++ b/src/Mono.Android/Android/IncludeAndroidResourcesFromAttribute.cs @@ -3,7 +3,7 @@ namespace Android { [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] - [Obsolete ("This attribute is deprecated and will be removed in a future release.")] + [Obsolete ("This attribute is not longer supported.", error: true)] public class IncludeAndroidResourcesFromAttribute : ReferenceFilesAttribute { public IncludeAndroidResourcesFromAttribute (string path) diff --git a/src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs b/src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs index 88941e5e649..83c7e6b0886 100644 --- a/src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs +++ b/src/Mono.Android/Android/NativeLibraryReferenceAttribute.cs @@ -3,7 +3,7 @@ namespace Android { [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] - [Obsolete ("This attribute is deprecated and will be removed in a future release.")] + [Obsolete ("This attribute is not longer supported.", error: true)] sealed public class NativeLibraryReferenceAttribute : ReferenceFilesAttribute { public NativeLibraryReferenceAttribute (string filename) diff --git a/src/Mono.Android/Android/ReferenceFilesAttribute.cs b/src/Mono.Android/Android/ReferenceFilesAttribute.cs index c73ebc394a2..b691d7a3544 100644 --- a/src/Mono.Android/Android/ReferenceFilesAttribute.cs +++ b/src/Mono.Android/Android/ReferenceFilesAttribute.cs @@ -1,7 +1,7 @@ using System; namespace Android { - [Obsolete ("This attribute is deprecated and will be removed in a future release.")] + [Obsolete ("This attribute is not longer supported.", error: true)] public abstract class ReferenceFilesAttribute : Attribute { internal ReferenceFilesAttribute () {} diff --git a/src/Mono.Android/Java.Interop/JavaLibraryReferenceAttribute.cs b/src/Mono.Android/Java.Interop/JavaLibraryReferenceAttribute.cs index a859cc23135..b62fd97858a 100644 --- a/src/Mono.Android/Java.Interop/JavaLibraryReferenceAttribute.cs +++ b/src/Mono.Android/Java.Interop/JavaLibraryReferenceAttribute.cs @@ -3,7 +3,7 @@ namespace Java.Interop { [AttributeUsage (AttributeTargets.Assembly, AllowMultiple = true)] - [Obsolete ("This attribute is deprecated and will be removed in a future release.")] + [Obsolete ("This attribute is not longer supported.", error: true)] public class JavaLibraryReferenceAttribute : Android.ReferenceFilesAttribute { public JavaLibraryReferenceAttribute (string filename) diff --git a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt.targets b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt.targets index 835083ed8d3..429c3a463b0 100644 --- a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt.targets +++ b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt.targets @@ -48,7 +48,6 @@ Copyright (C) 2019 Microsoft Corporation. All rights reserved. ExtraArgs="$(AndroidResgenExtraArgs)" ToolPath="$(AaptToolPath)" ToolExe="$(AaptToolExe)" - AdditionalAndroidResourcePaths="@(_AdditonalAndroidResourceCachePaths)" ApiLevel="$(_AndroidTargetSdkVersion)" AndroidUseLatestPlatformSdk="$(AndroidUseLatestPlatformSdk)" ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)" @@ -81,7 +80,6 @@ Copyright (C) 2019 Microsoft Corporation. All rights reserved. AssetDirectory="$(MonoAndroidAssetsDirIntermediate)" ToolPath="$(AaptToolPath)" ToolExe="$(AaptToolExe)" - AdditionalAndroidResourcePaths="@(_AdditonalAndroidResourceCachePaths)" ApiLevel="$(_AndroidTargetSdkVersion)" AndroidUseLatestPlatformSdk="$(AndroidUseLatestPlatformSdk)" ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)" diff --git a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt2.targets b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt2.targets index 4bfa41f4bd8..5cd02d6aca5 100644 --- a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt2.targets +++ b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Aapt2.targets @@ -50,7 +50,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. Condition=" '$(_AndroidUseAapt2)' == 'True' " > diff --git a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Designer.targets b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Designer.targets index a2750bbcb46..8aca9e217e2 100644 --- a/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Designer.targets +++ b/src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Designer.targets @@ -19,12 +19,6 @@ Copyright (C) 2016 Xamarin. All rights reserved. - - - - @@ -41,9 +35,6 @@ Copyright (C) 2016 Xamarin. All rights reserved. AndroidJavaLibrary - - AssemblyCache - LibraryImport diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/FilterAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/FilterAssemblies.cs index 4f7caf39bc3..c163a95ff7c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/FilterAssemblies.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/FilterAssemblies.cs @@ -43,7 +43,7 @@ public override bool RunTask () using (var pe = new PEReader (File.OpenRead (assemblyItem.ItemSpec))) { var reader = pe.GetMetadataReader (); var assemblyDefinition = reader.GetAssemblyDefinition (); - var targetFrameworkIdentifier = assemblyDefinition.GetTargetFrameworkIdentifier (reader); + var targetFrameworkIdentifier = GetTargetFrameworkIdentifier (assemblyDefinition, reader); if (string.Compare (targetFrameworkIdentifier, TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) == 0) { output.Add (assemblyItem); continue; @@ -71,6 +71,40 @@ public override bool RunTask () return !Log.HasLoggedErrors; } + string GetTargetFrameworkIdentifier (AssemblyDefinition assembly, MetadataReader reader) + { + string targetFrameworkIdentifier = null; + foreach (var handle in assembly.GetCustomAttributes ()) { + var attribute = reader.GetCustomAttribute (handle); + var name = reader.GetCustomAttributeFullName (attribute); + switch (name) { + case "System.Runtime.Versioning.TargetFrameworkAttribute": + var arguments = attribute.GetCustomAttributeArguments (); + foreach (var p in arguments.FixedArguments) { + // Of the form "MonoAndroid,Version=v8.1" + var value = p.Value?.ToString (); + if (!string.IsNullOrEmpty (value)) { + int commaIndex = value.IndexOf (",", StringComparison.Ordinal); + if (commaIndex != -1) { + targetFrameworkIdentifier = value.Substring (0, commaIndex); + break; + } + } + } + break; + case "Android.IncludeAndroidResourcesFromAttribute": + case "Android.NativeLibraryReferenceAttribute": + case "Java.Interop.JavaLibraryReferenceAttribute": + Log.LogCodedError ("XA0121", + $"Assembly '{reader.GetString (assembly.Name)}' is using '[assembly: {name}]', which is no longer supported. Use a newer version of this NuGet package or notify the library author."); + break; + default: + break; + } + } + return targetFrameworkIdentifier; + } + bool HasReference (MetadataReader reader) { foreach (var handle in reader.AssemblyReferences) { diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs deleted file mode 100644 index 205b7f6268b..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetAdditionalResourcesFromAssemblies.cs +++ /dev/null @@ -1,482 +0,0 @@ -using Microsoft.Build.Framework; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Reflection.Metadata; -using System.Reflection.PortableExecutable; -using System.Security.Cryptography; -using System.Text.RegularExpressions; -using System.Xml.Linq; -using Xamarin.Android.Tools; - -namespace Xamarin.Android.Tasks -{ - - public class GetAdditionalResourcesFromAssemblies : AndroidAsyncTask - { - public override string TaskPrefix => "GAR"; - - /// - /// Environment variable named XAMARIN_CACHEPATH that can be set - /// to override the default cache path. - /// - public const string CachePathEnvironmentVar = "%XAMARIN_CACHEPATH%"; - - /// - /// Base directory under the user's local app data folder that is used as the - /// default cache location. - /// - const string CacheBaseDir = "Xamarin"; - - /// - /// Assemblies whose resources are unzipped to a cache path rather than in-place. - /// - const string AssemblyNamePrefix = "Xamarin."; - - [Required] - public string AndroidSdkDirectory { get; set; } - - public string AndroidNdkDirectory { get; set; } - - [Required] - public ITaskItem[] Assemblies { get; set; } - - [Required] - public bool DesignTimeBuild { get; set; } - - [Required] - public string CacheFile { get; set; } - - string CachePath; - - internal const string AndroidSkipResourceExtraction = "AndroidSkipResourceExtraction"; - - public GetAdditionalResourcesFromAssemblies () - { - } - - readonly Regex regex = new Regex(@"(\$(\w+))\b"); - - readonly string[] extraPaths = new string[] { - Path.Combine ("extras", "android"), - Path.Combine ("extras", "google"), - }; - - string SubstituteEnvVariables (string path) - { - MatchEvaluator replaceEnvVar = (Match m) => { - var e = m.Groups [2].Value; - switch (e) { - case "ANDROID_SDK_PATH": - return AndroidSdkDirectory.TrimEnd (Path.DirectorySeparatorChar); - case "ANDROID_NDK_PATH": - //NOTE: AndroidNdkDirectory is not [Required] - if (string.IsNullOrEmpty (AndroidNdkDirectory)) { - goto default; - } - return AndroidNdkDirectory.TrimEnd (Path.DirectorySeparatorChar); - default: - var v = Environment.GetEnvironmentVariable (e); - if (!string.IsNullOrEmpty (v)) - return v; - return m.Groups [1].Value; - } - }; - - return regex.Replace (path, replaceEnvVar); - } - - internal static string ErrorMessage (CustomAttributeValue attributeValue) - { - if (attributeValue.NamedArguments.Length == 0) - return ""; - var arg = attributeValue.NamedArguments.FirstOrDefault (p => p.Name == "PackageName"); - if (arg.Name != null) { - string packageName = arg.Value as string; - if (packageName != null) - return string.Format ("Please install package: '{0}' available in SDK installer", packageName); - } - arg = attributeValue.NamedArguments.FirstOrDefault (p => p.Name == "InstallInstructions"); - if (arg.Name != null) { - string instInstructs = arg.Value as string; - if (instInstructs != null) - return "Installation instructions: " + instInstructs; - } - return null; - } - - void AddAttributeValue (ICollection items, CustomAttributeValue attributeValue, string errorCode, string errorFmt, - bool isDirectory, string fullPath, string attributeFullName) - { - LogCodedWarning ("XA0121", - $"Assembly '{Path.GetFileName (fullPath)}' is using a deprecated attribute '[assembly: {attributeFullName}]'. Use a newer version of this NuGet package or notify the library author."); - - if (attributeValue.NamedArguments.Length == 0 || attributeValue.FixedArguments.Length != 1) { - LogCodedWarning (errorCode, "Attribute {0} doesn't have expected one constructor agrument", attributeFullName); - return; - } - - var arg = attributeValue.FixedArguments.First (); - string path = arg.Value as string; - if (string.IsNullOrEmpty (path)) { - LogCodedWarning (errorCode, "Attribute {0} contructor argument is empty or not set to string", attributeFullName); - return; - } - path = SubstituteEnvVariables (path).TrimEnd (Path.DirectorySeparatorChar); - string baseDir = null; - var sourceUrl = attributeValue.NamedArguments.FirstOrDefault (p => p.Name == "SourceUrl"); - var embeddedArchive = attributeValue.NamedArguments.FirstOrDefault (p => p.Name == "EmbeddedArchive"); - var version = attributeValue.NamedArguments.FirstOrDefault (p => p.Name == "Version"); - var sha1sum = attributeValue.NamedArguments.FirstOrDefault (p => p.Name == "Sha1sum"); - var isXamarinAssembly = Path.GetFileName (fullPath).StartsWith (AssemblyNamePrefix, StringComparison.OrdinalIgnoreCase); - var assemblyDir = Path.Combine (CachePath, Path.GetFileNameWithoutExtension (fullPath)); - // upgrade the paths to not strip off the Xamarin. prefix as it might cause assembly - // collisions now that we cache everything here. - var oldAssemblyDir = Path.Combine (CachePath, Path.GetFileNameWithoutExtension (fullPath).Substring (isXamarinAssembly ? AssemblyNamePrefix.Length : 0)); - if (string.Compare (assemblyDir, oldAssemblyDir, StringComparison.OrdinalIgnoreCase) != 0 && Directory.Exists (oldAssemblyDir)) { - Directory.CreateDirectory (assemblyDir); - foreach (var oldDir in Directory.GetDirectories (oldAssemblyDir, "*", SearchOption.AllDirectories)) { - var newDir = oldDir.Replace (oldAssemblyDir, assemblyDir); - Directory.CreateDirectory (newDir); - } - foreach (string oldFile in Directory.GetFiles(oldAssemblyDir, "*.*", - SearchOption.AllDirectories)) { - var newFile = oldFile.Replace (oldAssemblyDir, assemblyDir); - Directory.CreateDirectory (Path.GetDirectoryName (newFile)); - File.Copy (oldFile, newFile, true); - } - Directory.Delete (oldAssemblyDir, recursive: true); - } - if (sourceUrl.Name != null) { - if (new Uri (sourceUrl.Value as string).IsFile) - assemblyDir = Path.GetDirectoryName (fullPath); - baseDir = MakeSureLibraryIsInPlace (assemblyDir, sourceUrl.Value as string, - version.Value as string, embeddedArchive.Value as string, sha1sum.Value as string); - } - if (!string.IsNullOrEmpty (baseDir) && !Path.IsPathRooted (path)) - path = Path.Combine (baseDir, path); - if ((isDirectory && Directory.Exists (path)) || - (!isDirectory && File.Exists (path))) { - items.Add (Path.GetFullPath (path).TrimEnd (Path.DirectorySeparatorChar)); - return; - } - if (!DesignTimeBuild) - LogCodedError (errorCode, errorFmt, ErrorMessage (attributeValue), path); - } - - bool ExtractArchive (string url, string file, string contentDir) - { - if (!File.Exists (file)) { - // this file is supposed to exist! why doesn't it. - return false; - } - if (!Directory.Exists (contentDir)) { - try { - Directory.CreateDirectory (contentDir); - LogMessage ("Extracting {0} to {1}", file, contentDir); - using (var zip = MonoAndroidHelper.ReadZipFile (file)) { - int extracted = 0; - var o = Math.Max(1, (zip.EntryCount / 10)); - Files.ExtractAll (zip, contentDir, (progress, total) => { - if ((progress % o) != 0 || extracted == progress || progress == 0) - return; - LogMessage ("Extracted {0} of {1} files", progress, total); - extracted = progress; - }); - } - } - catch (Exception e) { - LogCodedError ("XA5209", "Unzipping failed. Please download {0} and extract it to the {1} directory.", url, contentDir); - LogCodedError ("XA5209", "Reason: {0}", e.Message); - LogMessage (e.ToString (), MessageImportance.Low); - Directory.Delete (contentDir, true); - return false; - } - } - return true; - } - - bool IsValidDownload(string file, string sha1) - { - if (string.IsNullOrEmpty (sha1)) - return true; - - HashAlgorithm hashAlgorithm; - try { - hashAlgorithm = new SHA1Managed (); - } catch (InvalidOperationException exc) { - // FIPS-enabled Windows machines will fail here - Log.LogCodedWarning ("XA0120", $"Failed to use SHA1 hash algorithm: {exc}"); - return true; - } - - var hashFile = file + ".sha1"; - using (hashAlgorithm) { - if (File.Exists (hashFile) && string.Compare (File.ReadAllText (hashFile), sha1, StringComparison.InvariantCultureIgnoreCase) == 0) - return true; - - var hash = Files.HashFile (file, hashAlgorithm); - LogDebugMessage ("File : {0}", file); - LogDebugMessage ("SHA1 : {0}", hash); - LogDebugMessage ("Expected SHA1 : {0}", sha1); - - var isValid = string.Compare (hash, sha1, StringComparison.InvariantCultureIgnoreCase) == 0; - if (isValid) - File.WriteAllText (hashFile, hash); - - return isValid; - } - } - - void DoDownload (long totalBytes, long offset, Stream responseStream, Stream outputStream, Action progressCallback = null) - { - long readSoFar = offset; - byte [] buffer = new byte [8192]; - int bufferSize = buffer.Length; - int nread = 0; - float percent, tb = (float)totalBytes, lastPercent = 0; - outputStream.Seek (offset, SeekOrigin.Begin); - - while ((nread = responseStream.Read (buffer, 0, buffer.Length)) > 0) { - readSoFar += nread; - outputStream.Write (buffer, 0, nread); - percent = (float)readSoFar / tb * 100; - if (percent - lastPercent > 1) { - progressCallback?.Invoke (readSoFar, totalBytes, (int)percent); - lastPercent = percent; - } - outputStream.Flush (); - } - } - - void Download (string file, Uri uri, Action progressCallback = null) - { - var request = WebRequest.CreateHttp (uri); - int offset = 0; - if (File.Exists (file) && !MonoAndroidHelper.IsValidZip (file)) { - var fi = new FileInfo (file); - request.AddRange (fi.Length); - offset = (int)fi.Length; - LogMessage ("Partial download detected. Resuming from previous download progress."); - } - if (!File.Exists (file) || offset > 0) { - HttpWebResponse response = null; - try { - response = (HttpWebResponse)request.GetResponse (); - } - catch (WebException ex) { - var exceptionResponse = ex.Response as HttpWebResponse; - if (exceptionResponse?.StatusCode != HttpStatusCode.RequestedRangeNotSatisfiable) - throw; - // Download the entire file again. - request.Abort (); - request = WebRequest.CreateHttp (uri); - File.Delete (file); - offset = 0; - request.AddRange (0); - response = (HttpWebResponse)request.GetResponse (); - LogMessage ("Could not resume previous download. Starting again."); - } - if (response != null) { - long totalBytes = response.ContentLength + offset; - using (var responseStream = response.GetResponseStream ()) { - using (var outputStream = new FileStream (file, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { - DoDownload (totalBytes, offset, responseStream, outputStream, progressCallback); - } - } - } - } - } - - string MakeSureLibraryIsInPlace (string destinationBase, string url, string version, string embeddedArchive, string sha1) - { - if (string.IsNullOrEmpty (url)) - return null; - - LogDebugMessage ("Making sure we have {0} downloaded and extracted {1} from it...", url, embeddedArchive); - - string destinationDir = version == null ? destinationBase : Path.Combine (destinationBase, version); - bool createDestinationDirectory = !Directory.Exists (destinationDir); - if (createDestinationDirectory) - Directory.CreateDirectory (destinationDir); - - var hash = Files.HashString (url); - var uri = new Uri (url); - - var extraPath = extraPaths.FirstOrDefault (x => File.Exists (Path.Combine (AndroidSdkDirectory, x, embeddedArchive ?? String.Empty))); - - string zipDir = !uri.IsFile ? Path.Combine (CachePath, "zips") : destinationDir; - bool createZipDirectory = !Directory.Exists (zipDir); - if (createZipDirectory) - Directory.CreateDirectory (zipDir); - - string file = Path.Combine (zipDir, !uri.IsFile ? hash + ".zip" : Path.GetFileName (uri.AbsolutePath)); - if (string.IsNullOrEmpty (extraPath) && (!File.Exists (file) || !IsValidDownload (file, sha1) || !MonoAndroidHelper.IsValidZip (file))) { - if (DesignTimeBuild) { - LogDebugMessage ($"DesignTimeBuild={DesignTimeBuild}. Skipping download of {url}"); - return null; - } - - int progress = -1; - var downloadHandler = new Action((r,t,p) => { - if (p % 10 != 0 || progress == p) - return; - progress = p; - LogMessage ("\t({0}/{1}b), total {2:F1}%", r, - t, p); - }); - LogMessage (" Downloading {0} into {1}", url, zipDir); - try { - Download (file, uri, downloadHandler); - if (MonoAndroidHelper.IsValidZip (file)) - LogMessage (" Downloading Complete"); - else - LogCodedError ("XA5208", "Download succeeded but the zip file was not valid. Please do a clean build and try again."); - } catch (Exception e) { - LogCodedError ("XA5208", "Download failed. Please build again."); - LogCodedError ("XA5208", "Reason: {0}", e.GetBaseException ().Message); - LogMessage (e.ToString (), MessageImportance.Low); - } - } - else { - if (string.IsNullOrEmpty (extraPath)) - LogDebugMessage (" reusing existing archive: {0}", file); - else - LogDebugMessage (" found `{0}` in `{1}`", embeddedArchive, Path.Combine (AndroidSdkDirectory, extraPath)); - } - - string contentDir = string.IsNullOrEmpty (extraPath) ? Path.Combine (destinationDir, "content") : Path.Combine (AndroidSdkDirectory, extraPath); - - int attempt = 0; - while (attempt < 3 && !Log.HasLoggedErrors) { - var success = ExtractArchive (url, file, contentDir); - if (!success && Log.HasLoggedErrors) { - break; - } - - if (!string.IsNullOrEmpty (embeddedArchive)) { - string embeddedDir = Path.Combine (destinationDir, "embedded"); - success = ExtractArchive (string.Format ("{0}:{1}", url, embeddedArchive), Path.Combine (contentDir, embeddedArchive), embeddedDir); - if (success) { - contentDir = embeddedDir; - break; - } - if (Log.HasLoggedErrors) - break; - if (!success) { - LogWarning ("Expected File {0} does not exist. Trying to extract again.", Path.Combine (contentDir, embeddedArchive)); - if (Directory.Exists (contentDir)) - Directory.Delete (contentDir, recursive: true); - } - } else - break; - attempt++; - } - - if (string.IsNullOrEmpty (contentDir) || !Directory.Exists (contentDir)) { - if (createZipDirectory) - Directory.Delete (zipDir); - if (createDestinationDirectory) - Directory.Delete (destinationDir); - } - - return contentDir; - } - - public async override System.Threading.Tasks.Task RunTaskAsync () - { - if (Environment.GetEnvironmentVariable ("XA_DL_IGNORE_CERT_ERRROS") == "yesyesyes") { - ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; - LogDebugMessage (" Disabling download certificate validation callback."); - } - var androidResources = new HashSet (); - var javaLibraries = new HashSet (); - var nativeLibraries = new HashSet (); - var assemblies = new HashSet (); - - if (Assemblies == null) - return; - - var cacheFileFullPath = CacheFile; - if (!Path.IsPathRooted (cacheFileFullPath)) - cacheFileFullPath = Path.Combine (WorkingDirectory, cacheFileFullPath); - - // The cache location can be overriden by the (to be documented) XAMARIN_CACHEPATH - CachePath = Environment.ExpandEnvironmentVariables (CachePathEnvironmentVar); - CachePath = CachePath != CachePathEnvironmentVar - ? CachePath - : Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData), CacheBaseDir); - - foreach (var assemblyItem in Assemblies) { - if (bool.TryParse (assemblyItem.GetMetadata (AndroidSkipResourceExtraction), out bool value) && value) { - LogDebugMessage ($"Skipping {assemblyItem.ItemSpec} due to 'AndroidSkipResourceExtraction' == 'true' "); - continue; - } - string fullPath = Path.GetFullPath (assemblyItem.ItemSpec); - if (DesignTimeBuild && !File.Exists (fullPath)) { - LogWarning ("Failed to load '{0}'. Check the file exists or the project has been built.", fullPath); - continue; - } - if (assemblies.Contains (fullPath)) { - LogDebugMessage (" Skip assembly: {0}, it was already processed", fullPath); - continue; - } - // don't try to even load mscorlib it will fail. - if (string.Compare (Path.GetFileNameWithoutExtension (fullPath), "mscorlib", StringComparison.OrdinalIgnoreCase) == 0) - continue; - assemblies.Add (fullPath); - using (var pe = new PEReader (File.OpenRead (fullPath))) { - var reader = pe.GetMetadataReader (); - var assembly = reader.GetAssemblyDefinition (); - // Append source file name (without the Xamarin. prefix or extension) to the base folder - // This would help avoid potential collisions. - foreach (var handle in assembly.GetCustomAttributes ()) { - var attribute = reader.GetCustomAttribute (handle); - var fullName = reader.GetCustomAttributeFullName (attribute); - switch (fullName) { - case "Android.IncludeAndroidResourcesFromAttribute": - AddAttributeValue (androidResources, attribute.GetCustomAttributeArguments (), "XA5206", "{0}. Android resource directory {1} doesn't exist.", true, fullPath, fullName); - break; - case "Java.Interop.JavaLibraryReferenceAttribute": - AddAttributeValue (javaLibraries, attribute.GetCustomAttributeArguments (), "XA5207", "{0}. Java library file {1} doesn't exist.", false, fullPath, fullName); - break; - case "Android.NativeLibraryReferenceAttribute": - AddAttributeValue (nativeLibraries, attribute.GetCustomAttributeArguments (), "XA5210", "{0}. Native library file {1} doesn't exist.", false, fullPath, fullName); - break; - } - } - } - } - - if (Log.HasLoggedErrors) { - if (File.Exists (cacheFileFullPath)) - File.Delete (cacheFileFullPath); - return; - } - - var AdditionalAndroidResourcePaths = androidResources.ToArray (); - var AdditionalJavaLibraryReferences = javaLibraries.ToArray (); - var AdditionalNativeLibraryReferences = nativeLibraries - .Where (x => MonoAndroidHelper.GetNativeLibraryAbi (x) != null) - .ToArray (); - - var document = new XDocument ( - new XDeclaration ("1.0", "UTF-8", null), - new XElement ("Paths", - new XElement ("AdditionalAndroidResourcePaths", - AdditionalAndroidResourcePaths.Select(e => new XElement ("AdditionalAndroidResourcePath", e))), - new XElement ("AdditionalJavaLibraryReferences", - AdditionalJavaLibraryReferences.Select(e => new XElement ("AdditionalJavaLibraryReference", e))), - new XElement ("AdditionalNativeLibraryReferences", - AdditionalNativeLibraryReferences.Select(e => new XElement ("AdditionalNativeLibraryReference", e))) - )); - document.SaveIfChanged (cacheFileFullPath); - - LogDebugTaskItems (" AdditionalAndroidResourcePaths: ", AdditionalAndroidResourcePaths); - LogDebugTaskItems (" AdditionalJavaLibraryReferences: ", AdditionalJavaLibraryReferences); - LogDebugTaskItems (" AdditionalNativeLibraryReferences: ", AdditionalNativeLibraryReferences); - } - } -} diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ReadAdditionalResourcesFromAssemblyCache.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ReadAdditionalResourcesFromAssemblyCache.cs deleted file mode 100644 index c0d7478d0e4..00000000000 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ReadAdditionalResourcesFromAssemblyCache.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Xml.XPath; -using System.Xml.Linq; -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; - -namespace Xamarin.Android.Tasks -{ - public class ReadAdditionalResourcesFromAssemblyCache : AndroidTask { - public override string TaskPrefix => "RAR"; - - [Required] - public string CacheFile { get; set;} - - [Output] - public string[] AdditionalAndroidResourcePaths { get; set; } - - [Output] - public string[] AdditionalJavaLibraryReferences { get; set; } - - [Output] - public string[] AdditionalNativeLibraryReferences { get; set; } - - [Output] - public bool IsResourceCacheValid { get; set; } - - public ReadAdditionalResourcesFromAssemblyCache () - { - AdditionalAndroidResourcePaths = new string [0]; - AdditionalJavaLibraryReferences = new string [0]; - AdditionalNativeLibraryReferences = new string [0]; - } - - public override bool RunTask () - { - if (!File.Exists (CacheFile)) { - Log.LogDebugMessage ("{0} does not exist. No Additional Resources found", CacheFile); - return !Log.HasLoggedErrors; - } - var doc = XDocument.Load (CacheFile); - AdditionalAndroidResourcePaths = doc.GetPaths ("AdditionalAndroidResourcePaths", - "AdditionalAndroidResourcePath"); - AdditionalJavaLibraryReferences = doc.GetPaths ("AdditionalJavaLibraryReferences", - "AdditionalJavaLibraryReference"); - AdditionalNativeLibraryReferences = doc.GetPaths ("AdditionalNativeLibraryReferences", - "AdditionalNativeLibraryReference"); - - Log.LogDebugTaskItems (" AdditionalAndroidResourcePaths: ", AdditionalAndroidResourcePaths); - Log.LogDebugTaskItems (" AdditionalJavaLibraryReferences: ", AdditionalJavaLibraryReferences); - Log.LogDebugTaskItems (" AdditionalNativeLibraryReferences: ", AdditionalNativeLibraryReferences); - - IsResourceCacheValid = AdditionalAndroidResourcePaths.All (x => Directory.Exists (x)) && - AdditionalJavaLibraryReferences.All (x => File.Exists (x)) && - AdditionalNativeLibraryReferences.All (x => File.Exists (x)); - - Log.LogDebugMessage (" IsValid: {0}", IsResourceCacheValid); - - return !Log.HasLoggedErrors; - } - } -} - diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs index 2e7184713c7..58f9bcefba4 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs @@ -16,6 +16,8 @@ public class ResolveLibraryProjectImports : AndroidTask { public override string TaskPrefix => "RLP"; + internal const string AndroidSkipResourceExtraction = "AndroidSkipResourceExtraction"; + [Required] public string ImportsDirectory { get; set; } @@ -167,7 +169,7 @@ void Extract ( Log.LogDebugMessage ($"Skipping non-existent dependency '{assemblyPath}'."); continue; } - if (bool.TryParse (assemblyItem.GetMetadata (GetAdditionalResourcesFromAssemblies.AndroidSkipResourceExtraction), out skip) && skip) { + if (bool.TryParse (assemblyItem.GetMetadata (AndroidSkipResourceExtraction), out skip) && skip) { Log.LogDebugMessage ("Skipping resource extraction for '{0}' .", assemblyPath); continue; } 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 20dd0b9dc65..f7eb69f5c8f 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 @@ -42,30 +42,9 @@ public void DesignTimeBuild ([Values(false, true)] bool isRelease, [Values (fals var regEx = new Regex (@"(?([a-zA-Z_0-9])+)\slibrary_name=(?([0-9A-Za-z])+);", RegexOptions.Compiled | RegexOptions.Multiline ); var path = Path.Combine (Root, "temp", $"DesignTimeBuild_{isRelease}_{useManagedParser}_{useAapt2}"); - var cachePath = Path.Combine (path, "Cache"); - var envVar = new Dictionary () { - { "XAMARIN_CACHEPATH", cachePath }, - }; - var url = "http://dl-ssl.google.com/android/repository/build-tools_r24-macosx.zip"; - var hash = Files.HashString (url); - var zipPath = Path.Combine (cachePath, "zips", $"{hash}.zip"); - if (File.Exists (zipPath)) - File.Delete (zipPath); - - var extractedDir = Path.Combine (cachePath, "Lib1"); - if (Directory.Exists (extractedDir)) - Directory.Delete (extractedDir, recursive: true); - var lib = new XamarinAndroidLibraryProject () { ProjectName = "Lib1", IsRelease = isRelease, - AssemblyInfo = @"using System.Reflection; -using System.Runtime.CompilerServices; - -[assembly: Android.NativeLibraryReferenceAttribute (""android-N/renderscript/lib/packaged/x86/librsjni.so"", - SourceUrl="""+ url +@""", - Version=""1"", PackageName=""Lib1"")] -", }; lib.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", useManagedParser.ToString ()); lib.SetProperty ("AndroidUseAapt2", useAapt2.ToString ()); @@ -87,20 +66,15 @@ public void DesignTimeBuild ([Values(false, true)] bool isRelease, [Values (fals b.Verbosity = LoggerVerbosity.Diagnostic; b.ThrowOnBuildFailure = false; b.Target = "Compile"; - Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, parameters: new string [] { "DesignTimeBuild=true" }, environmentVariables: envVar), + Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, parameters: new string [] { "DesignTimeBuild=true" }), "first build failed"); - Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, "DesignTimeBuild=True. Skipping download of "), - "failed to skip the downloading of files."); var designTimeDesigner = Path.Combine (intermediateOutputPath, "designtime", "Resource.designer.cs"); if (useManagedParser) { FileAssert.Exists (designTimeDesigner, $"{designTimeDesigner} should have been created."); } WaitFor (1000); b.Target = "Build"; - Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, parameters: new string [] { "DesignTimeBuild=false" }, environmentVariables: envVar), "second build failed"); - Assert.IsFalse(b.Output.IsTargetSkipped ("_BuildAdditionalResourcesCache"), "_BuildAdditionalResourcesCache should have run."); - Assert.IsTrue (b.LastBuildOutput.ContainsText ($"Downloading {url}") || b.LastBuildOutput.ContainsText ($"reusing existing archive: {zipPath}"), $"{url} should have been downloaded."); - FileAssert.Exists (Path.Combine (extractedDir, "1", "content", "android-N", "aapt"), $"Files should have been extracted to {extractedDir}"); + Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, parameters: new string [] { "DesignTimeBuild=false" }), "second build failed"); FileAssert.Exists (Path.Combine (intermediateOutputPath, "R.txt"), "R.txt should exist after IncrementalClean!"); FileAssert.Exists (Path.Combine (intermediateOutputPath, "res.flag"), "res.flag should exist after IncrementalClean!"); if (useManagedParser) { @@ -125,13 +99,13 @@ public void CheckEmbeddedSupportLibraryResources () var proj = new XamarinAndroidApplicationProject () { IsRelease = true, PackageReferences = { - KnownPackages.SupportMediaCompat_25_4_0_1, - KnownPackages.SupportFragment_25_4_0_1, - KnownPackages.SupportCoreUtils_25_4_0_1, - KnownPackages.SupportCoreUI_25_4_0_1, - KnownPackages.SupportCompat_25_4_0_1, - KnownPackages.AndroidSupportV4_25_4_0_1, - KnownPackages.SupportV7AppCompat_25_4_0_1, + KnownPackages.SupportMediaCompat_27_0_2_1, + KnownPackages.SupportFragment_27_0_2_1, + KnownPackages.SupportCoreUtils_27_0_2_1, + KnownPackages.SupportCoreUI_27_0_2_1, + KnownPackages.SupportCompat_27_0_2_1, + KnownPackages.AndroidSupportV4_27_0_2_1, + KnownPackages.SupportV7AppCompat_27_0_2_1, }, TargetFrameworkVersion = "v7.1", }; @@ -274,12 +248,12 @@ public void Check9PatchFilesAreProcessed ([Values(false, true)] bool explicitCru proj.AndroidResources.Add (image1); } proj.References.Add (new BuildItem ("ProjectReference", "..\\Library1\\Library1.csproj")); - proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_21_0_3_0); - proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_21_0_3_0); - proj.PackageReferences.Add (KnownPackages.SupportV7MediaRouter_21_0_3_0); - proj.PackageReferences.Add (KnownPackages.GooglePlayServices_22_0_0_2); + proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1); + proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_27_0_2_1); + proj.PackageReferences.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1); + proj.PackageReferences.Add (KnownPackages.GooglePlayServicesMaps_42_1021_1); + proj.PackageReferences.Add (KnownPackages.Xamarin_Build_Download_0_4_11); proj.AndroidExplicitCrunch = explicitCrunch; - proj.SetProperty ("TargetFrameworkVersion", "v5.0"); using (var b = CreateApkBuilder (Path.Combine (projectPath, "Application1"), false, false)) { b.Verbosity = LoggerVerbosity.Diagnostic; Assert.IsTrue (b.Build (proj), "Build should have succeeded."); @@ -294,18 +268,17 @@ public void Check9PatchFilesAreProcessed ([Values(false, true)] bool explicitCru proj.IntermediateOutputPath); png = PNGChecker.LoadFromBytes (data); Assert.IsTrue (png.Is9Patch, "image2.9.png should have been processed into a 9 patch image."); - data = ZipHelper.ReadFileFromZip (path, "res/drawable-hdpi-v4/common_signin_btn_icon_normal_dark.9.png"); - Assert.IsNotNull (data, "common_signin_btn_icon_normal_dark.9.png should be in {0}android/bin/packaged_resources", + data = ZipHelper.ReadFileFromZip (path, "res/drawable-hdpi-v4/common_google_signin_btn_icon_dark_normal_background.9.png"); + Assert.IsNotNull (data, "common_google_signin_btn_icon_dark_normal_background.9.png.png should be in {0}android/bin/packaged_resources", proj.IntermediateOutputPath); png = PNGChecker.LoadFromBytes (data); - Assert.IsTrue (png.Is9Patch, "common_signin_btn_icon_normal_dark.9.png should have been processed into a 9 patch image."); + Assert.IsTrue (png.Is9Patch, "common_google_signin_btn_icon_dark_normal_background.9.png should have been processed into a 9 patch image."); Directory.Delete (Path.Combine (Root,projectPath), recursive: true); } } } [Test] - [NonParallelizable] /// /// Based on https://bugzilla.xamarin.com/show_bug.cgi?id=29263 /// @@ -421,10 +394,8 @@ protected override void OnClick() } }" }); - proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_22_1_1_1); - proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_22_1_1_1); - proj.PackageReferences.Add (KnownPackages.SupportV7Palette_22_1_1_1); - proj.SetProperty ("TargetFrameworkVersion", "v5.0"); + proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1); + proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_27_0_2_1); using (var libb = CreateDllBuilder (Path.Combine (projectPath, lib.ProjectName), cleanupOnDispose: false)) using (var b = CreateApkBuilder (Path.Combine (projectPath, proj.ProjectName), cleanupOnDispose: false)) { Assert.IsTrue (libb.Build (lib), "Library Build should have succeeded."); @@ -1023,9 +994,8 @@ public void CheckFilesAreRemoved () { } }, PackageReferences = { - new Package (KnownPackages.AndroidSupportV13_21_0_3_0, audoAddReferences:true), - new Package (KnownPackages.AndroidSupportV4_21_0_3_0, audoAddReferences:true), - new Package (KnownPackages.SupportV7AppCompat_21_0_3_0, audoAddReferences:true), + KnownPackages.SupportV7AppCompat_27_0_2_1, + KnownPackages.AndroidSupportV4_27_0_2_1, }, }; proj.SetProperty (KnownProperties.TargetFrameworkVersion, "v5.1"); @@ -1183,13 +1153,13 @@ public void BuildAppWithManagedResourceParserAndLibraries () new BuildItem.ProjectReference (@"..\Lib1\Lib1.csproj", libProj.ProjectName, libProj.ProjectGuid), }, PackageReferences = { - KnownPackages.SupportMediaCompat_25_4_0_1, - KnownPackages.SupportFragment_25_4_0_1, - KnownPackages.SupportCoreUtils_25_4_0_1, - KnownPackages.SupportCoreUI_25_4_0_1, - KnownPackages.SupportCompat_25_4_0_1, - KnownPackages.AndroidSupportV4_25_4_0_1, - KnownPackages.SupportV7AppCompat_25_4_0_1, + KnownPackages.SupportMediaCompat_27_0_2_1, + KnownPackages.SupportFragment_27_0_2_1, + KnownPackages.SupportCoreUtils_27_0_2_1, + KnownPackages.SupportCoreUI_27_0_2_1, + KnownPackages.SupportCompat_27_0_2_1, + KnownPackages.AndroidSupportV4_27_0_2_1, + KnownPackages.SupportV7AppCompat_27_0_2_1, }, }; appProj.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", "True"); 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 11edc2575c5..8e8bb2000a0 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 @@ -29,7 +29,6 @@ public void BuildBasicBindingLibrary (string classParser) "ResolveLibraryProjects", "BuildDocumentation", "_ResolveLibraryProjectImports", - "_BuildAdditionalResourcesCache", "CoreCompile", }; @@ -114,7 +113,7 @@ public void BuildAarBindigLibraryWithNuGetPackageOfJar (string classParser) UseLatestPlatformSdk = true, IsRelease = true, }; - proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_22_1_1_1); + proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1); proj.Jars.Add (new AndroidItem.LibraryProjectZip ("Jars\\android-crop-1.0.1.aar") { WebContent = "https://jcenter.bintray.com/com/soundcloud/android/android-crop/1.0.1/android-crop-1.0.1.aar" }); @@ -126,9 +125,9 @@ public void BuildAarBindigLibraryWithNuGetPackageOfJar (string classParser) public "; proj.AndroidClassParser = classParser; - var b = CreateDllBuilder (Path.Combine ("temp", TestName)); - Assert.IsTrue (b.Build (proj), "Build should have succeeded."); - b.Dispose (); + using (var b = CreateDllBuilder ()) { + Assert.IsTrue (b.Build (proj), "Build should have succeeded."); + } } [Test] @@ -141,7 +140,7 @@ public void BuildLibraryZipBindigLibraryWithAarOfJar (string classParser) IsRelease = true, }; proj.AndroidClassParser = classParser; - proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_22_1_1_1); + proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1); proj.Jars.Add (new AndroidItem.LibraryProjectZip ("Jars\\aFileChooserBinaries.zip") { WebContentFileNameFromAzure = "aFileChooserBinaries.zip" }); @@ -185,9 +184,9 @@ public override Java.Lang.Object LoadInBackground () } }" }); - var b = CreateDllBuilder (Path.Combine ("temp", TestName), false, false); - Assert.IsTrue (b.Build (proj), "Build should have succeeded."); - b.Dispose (); + using (var b = CreateDllBuilder ()) { + Assert.IsTrue (b.Build (proj), "Build should have succeeded."); + } } [Test] @@ -416,7 +415,7 @@ public void RemoveEventHandlerResolution () Xamarin.ActionbarSherlockBinding.Views ", }; - binding.PackageReferences.Add (KnownPackages.AndroidSupportV4_22_1_1_1); + binding.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1); using (var bindingBuilder = CreateDllBuilder (Path.Combine ("temp", "RemoveEventHandlerResolution", "Binding"))) { Assert.IsTrue (bindingBuilder.Build (binding), "binding build should have succeeded"); } 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 3ab4b84f225..421f7ea1ec6 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 @@ -1534,25 +1534,6 @@ public void BuildApplicationCheckThatAddStaticResourcesTargetDoesNotRerun () } } - [Test] - [Ignore ("Re enable when MergeResources work is complete")] - public void AaptErrorWhenDuplicateStringEntry () - { - var proj = new XamarinAndroidApplicationProject (); - using (var b = CreateApkBuilder ("temp/BuildBasicApplicationAaptErrorWithDuplicateEntry")) { - // Add a library project so that aapt gets multiple resource directory to include - proj.PackageReferences.Add (KnownPackages.SupportV7CardView); - proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\values\\ExtraStrings.xml") { - TextContent = () => @"NoneNone", - }); - - b.ThrowOnBuildFailure = false; - Assert.IsFalse (b.Build (proj), "Build should fail with an aapt error about duplicated string res entries"); - StringAssertEx.Contains ("Resource entry Common.None is already defined", b.LastBuildOutput); - Assert.IsTrue (b.Clean (proj), "Clean should have succeeded"); - } - } - [Test] public void CheckJavaError () { @@ -1623,10 +1604,10 @@ public void XA5213IsRaisedWhenOutOfMemoryErrorIsThrown () + "\n}", Encoding = Encoding.ASCII }); - proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_21_0_3_0); - proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_21_0_3_0); - proj.PackageReferences.Add (KnownPackages.SupportV7MediaRouter_21_0_3_0); - proj.PackageReferences.Add (KnownPackages.GooglePlayServices_22_0_0_2); + proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1); + proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_27_0_2_1); + proj.PackageReferences.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1); + proj.PackageReferences.Add (KnownPackages.GooglePlayServicesMaps_42_1021_1); proj.SetProperty ("TargetFrameworkVersion", "v5.0"); proj.SetProperty ("AndroidEnableMultiDex", "True"); proj.SetProperty (proj.DebugProperties, "JavaMaximumHeapSize", "64m"); @@ -1823,25 +1804,23 @@ public void CheckLintConfigMerging () } [Test] - [NonParallelizable] /// /// 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.AndroidSupportV4_22_1_1_1); - proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_22_1_1_1); + proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1); + proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_27_0_2_1); proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\values\\Styles.xml") { TextContent = () => @"