From e3862a35335f6155f1a1edfb45b185f3b2375034 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Thu, 29 Mar 2018 17:50:40 +0900 Subject: [PATCH] [msbuild][r8] add r8 support to alter dx, proguard and desugar. See https://github.com/xamarin/xamarin-android/issues/1423 for details. multidex support is not done yet (needs to investigate what's expected there). Xamarin.Android.sln has a lot of changed lines because they had wrong ProjectTypeGuids (maybe regression from changes to .csproj from .*proj). --- Documentation/guides/BuildProcess.md | 7 + Xamarin.Android.sln | 16 ++ build-tools/r8/r8.csproj | 9 - external/depot_tools.tpnitems | 9 + external/r8.tpnitems | 9 + .../Test/Mono.Android-Tests.csproj | 2 + .../Tasks/Proguard.cs | 37 ++-- src/Xamarin.Android.Build.Tasks/Tasks/R8.cs | 173 ++++++++++++++++++ .../BuildTest.OSS.cs | 28 +++ .../Xamarin.Android.Build.Tests/BuildTest.cs | 6 +- .../Android/KnownProperties.cs | 1 + .../XamarinAndroidApplicationProject.cs | 5 + .../Xamarin.Android.Build.Tasks.csproj | 7 + .../Xamarin.Android.Common.targets | 90 ++++++++- src/r8/r8.csproj | 18 ++ {build-tools => src}/r8/r8.props | 0 {build-tools => src}/r8/r8.targets | 5 + 17 files changed, 385 insertions(+), 37 deletions(-) delete mode 100644 build-tools/r8/r8.csproj create mode 100644 external/depot_tools.tpnitems create mode 100644 external/r8.tpnitems create mode 100644 src/Xamarin.Android.Build.Tasks/Tasks/R8.cs create mode 100644 src/r8/r8.csproj rename {build-tools => src}/r8/r8.props (100%) rename {build-tools => src}/r8/r8.targets (94%) diff --git a/Documentation/guides/BuildProcess.md b/Documentation/guides/BuildProcess.md index 0d21fa60033..90bf661ad98 100644 --- a/Documentation/guides/BuildProcess.md +++ b/Documentation/guides/BuildProcess.md @@ -209,6 +209,9 @@ when packaing Release applications. This property is `False` by default. +- **AndroidEnableD8** – A boolean property that determines + whether or not use Google's new dexer (dx.jar alternative). + - **AndroidEnableMultiDex** – A boolean property that determines whether or not multi-dex support will be used in the final `.apk`. @@ -419,6 +422,10 @@ when packaing Release applications. This property should be `True` for Debug builds, and `False` for Release projects. +- **AndroidUseR8** – A boolean property that determines + whether or not use Google's new Java code shlinker (proguard + alternative). + - **AotAssemblies** – A boolean property that determines whether or not assemblies will be Ahead-of-Time compiled into native code and included in the `.apk`. diff --git a/Xamarin.Android.sln b/Xamarin.Android.sln index 8b18ad6ba9d..76b0208d1ea 100644 --- a/Xamarin.Android.sln +++ b/Xamarin.Android.sln @@ -123,6 +123,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Tools.Andro EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Tools.AndroidSdk-Tests", "external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Tests\Xamarin.Android.Tools.AndroidSdk-Tests.csproj", "{1E5501E8-49C1-4659-838D-CC9720C5208F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "r8", "src\r8\r8.csproj", "{1BAFA0CC-0377-46CE-AB7B-7BB2E7B62F63}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "proprietary", "build-tools\proprietary\proprietary.csproj", "{D93CAC27-3893-42A3-99F1-2BCA72E186F4}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "download-bundle", "build-tools\download-bundle\download-bundle.csproj", "{1DA0CB12-5508-4E83-A242-0C8D6D99A49B}" @@ -358,6 +359,18 @@ Global {1DA0CB12-5508-4E83-A242-0C8D6D99A49B}.Debug|AnyCPU.Build.0 = Debug|AnyCPU {1DA0CB12-5508-4E83-A242-0C8D6D99A49B}.Release|AnyCPU.ActiveCfg = Release|AnyCPU {1DA0CB12-5508-4E83-A242-0C8D6D99A49B}.Release|AnyCPU.Build.0 = Release|AnyCPU + {B7A457E6-9CB6-43F6-BFD6-14D5397FB98D}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {B7A457E6-9CB6-43F6-BFD6-14D5397FB98D}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {B7A457E6-9CB6-43F6-BFD6-14D5397FB98D}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {B7A457E6-9CB6-43F6-BFD6-14D5397FB98D}.Release|AnyCPU.Build.0 = Release|Any CPU + {53E4ABF0-1085-45F9-B964-DCAE4B819998}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {53E4ABF0-1085-45F9-B964-DCAE4B819998}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {53E4ABF0-1085-45F9-B964-DCAE4B819998}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {53E4ABF0-1085-45F9-B964-DCAE4B819998}.Release|AnyCPU.Build.0 = Release|Any CPU + {1BAFA0CC-0377-46CE-AB7B-7BB2E7B62F63}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {1BAFA0CC-0377-46CE-AB7B-7BB2E7B62F63}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {1BAFA0CC-0377-46CE-AB7B-7BB2E7B62F63}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {1BAFA0CC-0377-46CE-AB7B-7BB2E7B62F63}.Release|AnyCPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -420,6 +433,9 @@ Global {1E5501E8-49C1-4659-838D-CC9720C5208F} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483} {D93CAC27-3893-42A3-99F1-2BCA72E186F4} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62} {1DA0CB12-5508-4E83-A242-0C8D6D99A49B} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62} + {B7A457E6-9CB6-43F6-BFD6-14D5397FB98D} = {864062D3-A415-4A6F-9324-5820237BA058} + {53E4ABF0-1085-45F9-B964-DCAE4B819998} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483} + {1BAFA0CC-0377-46CE-AB7B-7BB2E7B62F63} = {04E3E11E-B47D-4599-8AFC-50515A95E715} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {53A1F287-EFB2-4D97-A4BB-4A5E145613F6} diff --git a/build-tools/r8/r8.csproj b/build-tools/r8/r8.csproj deleted file mode 100644 index ea1fb7870e7..00000000000 --- a/build-tools/r8/r8.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - Debug - - - - - - diff --git a/external/depot_tools.tpnitems b/external/depot_tools.tpnitems new file mode 100644 index 00000000000..7b261a2934d --- /dev/null +++ b/external/depot_tools.tpnitems @@ -0,0 +1,9 @@ + + + + + $(MSBuildThisFileDirectory)\depot_tools\LICENSE + https://chromium.googlesource.com/chromium/tools/depot_tools.git + + + diff --git a/external/r8.tpnitems b/external/r8.tpnitems new file mode 100644 index 00000000000..8d945808d81 --- /dev/null +++ b/external/r8.tpnitems @@ -0,0 +1,9 @@ + + + + + $(MSBuildThisFileDirectory)\r8\LICENSE + https://r8.googlesource.com/r8/ + + + diff --git a/src/Mono.Android/Test/Mono.Android-Tests.csproj b/src/Mono.Android/Test/Mono.Android-Tests.csproj index 7b01efbe6ce..ef69fabf413 100644 --- a/src/Mono.Android/Test/Mono.Android-Tests.csproj +++ b/src/Mono.Android/Test/Mono.Android-Tests.csproj @@ -19,6 +19,8 @@ armeabi-v7a;x86 False false + true + true diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs index 58963235d51..20fa256108d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs @@ -41,23 +41,17 @@ public class Proguard : ToolTask [Required] public string ProguardJarOutput { get; set; } - [Required] public string ProguardGeneratedReferenceConfiguration { get; set; } - - [Required] public string ProguardGeneratedApplicationConfiguration { get; set; } - - [Required] public string ProguardCommonXamarinConfiguration { get; set; } + [Required] public string ProguardConfigurationFiles { get; set; } public ITaskItem[] JavaLibrariesToEmbed { get; set; } - public ITaskItem[] ExternalJavaLibraries { get; set; } + public ITaskItem[] JavaLibrariesToReference { get; set; } - public ITaskItem[] DoNotPackageJavaLibraries { get; set; } - public bool UseProguard { get; set; } public string JavaOptions { get; set; } @@ -86,14 +80,13 @@ public override bool Execute () Log.LogDebugMessage (" JavaPlatformJarPath: {0}", JavaPlatformJarPath); Log.LogDebugMessage (" ClassesOutputDirectory: {0}", ClassesOutputDirectory); Log.LogDebugMessage (" AcwMapFile: {0}", AcwMapFile); - Log.LogDebugMessage (" ProguardGeneratedApplicationConfiguration: {0}", ProguardGeneratedApplicationConfiguration); Log.LogDebugMessage (" ProguardJarOutput: {0}", ProguardJarOutput); Log.LogDebugTaskItems (" ProguardGeneratedReferenceConfiguration:", ProguardGeneratedReferenceConfiguration); Log.LogDebugTaskItems (" ProguardGeneratedApplicationConfiguration:", ProguardGeneratedApplicationConfiguration); Log.LogDebugTaskItems (" ProguardCommonXamarinConfiguration:", ProguardCommonXamarinConfiguration); Log.LogDebugTaskItems (" ProguardConfigurationFiles:", ProguardConfigurationFiles); - Log.LogDebugTaskItems (" ExternalJavaLibraries:", ExternalJavaLibraries); - Log.LogDebugTaskItems (" DoNotPackageJavaLibraries:", DoNotPackageJavaLibraries); + Log.LogDebugTaskItems (" JavaLibrariesToEmbed:", JavaLibrariesToEmbed); + Log.LogDebugTaskItems (" JavaLibrariesToReference:", JavaLibrariesToReference); Log.LogDebugMessage (" UseProguard: {0}", UseProguard); Log.LogDebugMessage (" EnableLogging: {0}", EnableLogging); Log.LogDebugMessage (" DumpOutput: {0}", DumpOutput); @@ -139,15 +132,9 @@ protected override string GenerateCommandLineCommands () // skip invalid lines } - var injars = new List (); - var libjars = new List (); - injars.Add (classesZip); - if (JavaLibrariesToEmbed != null) - foreach (var jarfile in JavaLibrariesToEmbed) - injars.Add (jarfile.ItemSpec); - - using (var xamcfg = File.Create (ProguardCommonXamarinConfiguration)) - GetType ().Assembly.GetManifestResourceStream ("proguard_xamarin.cfg").CopyTo (xamcfg); + if (!string.IsNullOrWhiteSpace (ProguardCommonXamarinConfiguration)) + using (var xamcfg = File.Create (ProguardCommonXamarinConfiguration)) + GetType ().Assembly.GetManifestResourceStream ("proguard_xamarin.cfg").CopyTo (xamcfg); var configs = ProguardConfigurationFiles .Replace ("{sdk.dir}", AndroidSdkDirectory + Path.DirectorySeparatorChar) @@ -168,9 +155,15 @@ protected override string GenerateCommandLineCommands () Log.LogWarning ("Proguard configuration file '{0}' was not found.", file); } + var injars = new List (); + var libjars = new List (); + injars.Add (classesZip); + if (JavaLibrariesToEmbed != null) + foreach (var jarfile in JavaLibrariesToEmbed) + injars.Add (jarfile.ItemSpec); libjars.Add (JavaPlatformJarPath); - if (ExternalJavaLibraries != null) - foreach (var jarfile in ExternalJavaLibraries.Select (p => p.ItemSpec)) + if (JavaLibrariesToReference != null) + foreach (var jarfile in JavaLibrariesToReference.Select (p => p.ItemSpec)) libjars.Add (jarfile); cmd.AppendSwitchUnquotedIfNotNull ("-injars ", "\"'" + string.Join ($"'{ProguardInputJarFilter}{Path.PathSeparator}'", injars.Distinct ()) + $"'{ProguardInputJarFilter}\""); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs b/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs new file mode 100644 index 00000000000..afc758ae243 --- /dev/null +++ b/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs @@ -0,0 +1,173 @@ +// Copyright (C) 2018 Xamarin, Inc. All rights reserved. + +using System; +using System.Linq; +using System.IO; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using System.Text; +using System.Collections.Generic; +using Xamarin.Android.Tools; + +namespace Xamarin.Android.Tasks +{ + + public class R8 : JavaToolTask + { + [Required] + public string R8JarPath { get; set; } + + [Required] + public string OutputDirectory { get; set; } + + public string Configuration { get; set; } + + // It is loaded to calculate --min-api, which is used by desugaring part to determine which levels of desugaring it performs. + [Required] + public string AndroidManifestFile { get; set; } + + // general r8 feature options. + public bool EnableDesugar { get; set; } + public bool EnableMinify { get; set; } // The Task has the option, but it is not supported at all. + public bool EnableTreeShaking { get; set; } + + // Java libraries to embed or reference + [Required] + public string ClassesZip { get; set; } + [Required] + public string JavaPlatformJarPath { get; set; } + public ITaskItem [] JavaLibrariesToEmbed { get; set; } + public ITaskItem [] JavaLibrariesToReference { get; set; } + + // used for proguard configuration settings + [Required] + public string AndroidSdkDirectory { get; set; } + [Required] + public string AcwMapFile { get; set; } + public string ProguardGeneratedReferenceConfiguration { get; set; } + public string ProguardGeneratedApplicationConfiguration { get; set; } + public string ProguardCommonXamarinConfiguration { get; set; } + [Required] + public string ProguardConfigurationFiles { get; set; } + public string ProguardMappingOutput { get; set; } + + // multidex + public bool EnableMultiDex { get; set; } + public string MultiDexMainDexListFile { get; set; } + + public string R8ExtraArguments { get; set; } + + public override bool Execute () + { + Log.LogDebugMessage ("R8 Task"); + Log.LogDebugTaskItems (" R8JarPath: ", R8JarPath); + Log.LogDebugTaskItems (" OutputDirectory: ", OutputDirectory); + Log.LogDebugTaskItems (" AndroidManifestFile: ", AndroidManifestFile); + Log.LogDebugMessage (" Configuration: {0}", Configuration); + Log.LogDebugTaskItems (" JavaPlatformJarPath: ", JavaPlatformJarPath); + Log.LogDebugTaskItems (" ClassesZip: ", ClassesZip); + Log.LogDebugTaskItems (" JavaLibrariesToEmbed: ", JavaLibrariesToEmbed); + Log.LogDebugTaskItems (" JavaLibrariesToReference: ", JavaLibrariesToReference); + Log.LogDebugMessage (" EnableDesugar: {0}", EnableDesugar); + Log.LogDebugMessage (" EnableTreeShaking: {0}", EnableTreeShaking); + Log.LogDebugTaskItems (" AndroidSdkDirectory:", AndroidSdkDirectory); + Log.LogDebugTaskItems (" AcwMapFile: ", AcwMapFile); + Log.LogDebugTaskItems (" ProguardGeneratedReferenceConfiguration:", ProguardGeneratedReferenceConfiguration); + Log.LogDebugTaskItems (" ProguardGeneratedApplicationConfiguration:", ProguardGeneratedApplicationConfiguration); + Log.LogDebugTaskItems (" ProguardCommonXamarinConfiguration:", ProguardCommonXamarinConfiguration); + Log.LogDebugTaskItems (" ProguardConfigurationFiles:", ProguardConfigurationFiles); + Log.LogDebugTaskItems (" ProguardMappingOutput:", ProguardMappingOutput); + Log.LogDebugMessage (" EnableMultiDex: {0}", EnableMultiDex); + Log.LogDebugTaskItems (" MultiDexMainDexListFile: ", MultiDexMainDexListFile); + Log.LogDebugTaskItems (" R8ExtraArguments: ", R8ExtraArguments); + + return base.Execute (); + } + + protected override string GenerateCommandLineCommands () + { + var cmd = new CommandLineBuilder (); + + cmd.AppendSwitchIfNotNull ("-jar ", R8JarPath); + + if (!string.IsNullOrEmpty (R8ExtraArguments)) + cmd.AppendSwitch (R8ExtraArguments); // it should contain "--dex". + if (Configuration.Equals ("Debug", StringComparison.OrdinalIgnoreCase)) + cmd.AppendSwitch ("--debug"); + + // generating proguard application configuration + if (EnableTreeShaking) { + var acwLines = File.ReadAllLines (AcwMapFile); + using (var appcfg = File.CreateText (ProguardGeneratedApplicationConfiguration)) + for (int i = 0; i + 2 < acwLines.Length; i += 3) + try { + var line = acwLines [i + 2]; + var java = line.Substring (line.IndexOf (';') + 1); + appcfg.WriteLine ("-keep class " + java + " { *; }"); + } catch { + // skip invalid lines + } + if (!string.IsNullOrWhiteSpace (ProguardCommonXamarinConfiguration)) + using (var xamcfg = File.Create (ProguardCommonXamarinConfiguration)) + GetType ().Assembly.GetManifestResourceStream ("proguard_xamarin.cfg").CopyTo (xamcfg); + var configs = ProguardConfigurationFiles + .Replace ("{sdk.dir}", AndroidSdkDirectory + Path.DirectorySeparatorChar) + .Replace ("{intermediate.common.xamarin}", ProguardCommonXamarinConfiguration) + .Replace ("{intermediate.references}", ProguardGeneratedReferenceConfiguration) + .Replace ("{intermediate.application}", ProguardGeneratedApplicationConfiguration) + .Replace ("{project}", string.Empty) // current directory anyways. + .Split (';') + .Select (s => s.Trim ()) + .Where (s => !string.IsNullOrWhiteSpace (s)); + var enclosingChar = "\""; + foreach (var file in configs) { + if (File.Exists (file)) + cmd.AppendSwitchIfNotNull ("--pg-conf ", file); + else + Log.LogWarning ("Proguard configuration file '{0}' was not found.", file); + } + cmd.AppendSwitchIfNotNull ("--pg-map-output ", ProguardMappingOutput); + + // multidexing + if (EnableMultiDex) { + if (!string.IsNullOrWhiteSpace (MultiDexMainDexListFile) && File.Exists (MultiDexMainDexListFile)) + cmd.AppendSwitchIfNotNull ("--main-dex-list ", MultiDexMainDexListFile); + else + Log.LogWarning ($"MultiDex is enabled, but main dex list file '{MultiDexMainDexListFile}' does not exist."); + } + } + + // desugaring + var doc = AndroidAppManifest.Load (AndroidManifestFile, MonoAndroidHelper.SupportedVersions); + int minApiVersion = doc.MinSdkVersion == null ? 4 : (int)doc.MinSdkVersion; + cmd.AppendSwitchIfNotNull ("--min-api ", minApiVersion.ToString ()); + + if (!EnableTreeShaking) + cmd.AppendSwitch ("--no-tree-shaking"); + if (!EnableDesugar) + cmd.AppendSwitch ("--no-desugaring"); + if (!EnableMinify) + cmd.AppendSwitch ("--no-minification"); + + var injars = new List (); + var libjars = new List (); + injars.Add (ClassesZip); + if (JavaLibrariesToEmbed != null) + foreach (var jarfile in JavaLibrariesToEmbed) + injars.Add (jarfile.ItemSpec); + libjars.Add (JavaPlatformJarPath); + if (JavaLibrariesToReference != null) + foreach (var jarfile in JavaLibrariesToReference.Select (p => p.ItemSpec)) + libjars.Add (jarfile); + + cmd.AppendSwitchIfNotNull ("--output ", OutputDirectory); + foreach (var jar in libjars) + cmd.AppendSwitchIfNotNull ("--lib ", jar); + foreach (var jar in injars) + cmd.AppendFileNameIfNotNull (jar); + + return cmd.ToString (); + } + } + +} diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.OSS.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.OSS.cs index 97352581de6..0e9e5ccbd4f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.OSS.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.OSS.cs @@ -70,21 +70,49 @@ public partial class BuildTest : BaseTest /* isRelease */ true, /* enableProguard */ true, /* useLatestSdk */ true, + /* useR8 */ false, }, new Object [] { /* isRelease */ true, /* enableProguard */ false, /* useLatestSdk */ true, + /* useR8 */ false, }, new Object [] { /* isRelease */ false, /* enableProguard */ true, /* useLatestSdk */ true, + /* useR8 */ false, }, new Object [] { /* isRelease */ false, /* enableProguard */ false, /* useLatestSdk */ true, + /* useR8 */ false, + }, + new Object [] { + /* isRelease */ true, + /* enableProguard */ true, + /* useLatestSdk */ true, + /* useR8 */ true, + }, + new Object [] { + /* isRelease */ true, + /* enableProguard */ false, + /* useLatestSdk */ true, + /* useR8 */ true, + }, + new Object [] { + /* isRelease */ false, + /* enableProguard */ true, + /* useLatestSdk */ true, + /* useR8 */ true, + }, + new Object [] { + /* isRelease */ false, + /* enableProguard */ false, + /* useLatestSdk */ true, + /* useR8 */ true, }, }; static object [] TakeSimpleFlag = 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 164d5987d28..91201ac91ec 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 @@ -470,10 +470,10 @@ public void BuildAotApplicationAndBundle (string supportedAbis, bool enableLLVM, [Test] [TestCaseSource ("ProguardChecks")] - public void BuildProguardEnabledProject (bool isRelease, bool enableProguard, bool useLatestSdk) + public void BuildProguardEnabledProject (bool isRelease, bool enableProguard, bool useLatestSdk, bool useR8) { - var proj = new XamarinAndroidApplicationProject () { IsRelease = isRelease, EnableProguard = enableProguard, UseLatestPlatformSdk = useLatestSdk, TargetFrameworkVersion = useLatestSdk ? "v7.1" : "v5.0" }; - using (var b = CreateApkBuilder (Path.Combine ("temp", $"BuildProguard Enabled Project(1){isRelease}{enableProguard}{useLatestSdk}"))) { + var proj = new XamarinAndroidApplicationProject () { IsRelease = isRelease, EnableProguard = enableProguard, UseR8 = useR8, UseLatestPlatformSdk = useLatestSdk, TargetFrameworkVersion = useLatestSdk ? "v7.1" : "v5.0" }; + using (var b = CreateApkBuilder (Path.Combine ("temp", $"BuildProguard Enabled Project(1){isRelease}{enableProguard}{useLatestSdk}{useR8}"))) { Assert.IsTrue (b.Build (proj), "Build should have succeeded."); if (isRelease && enableProguard) { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownProperties.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownProperties.cs index c0d0ca37714..b6c3de96664 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownProperties.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/KnownProperties.cs @@ -17,6 +17,7 @@ public static class KnownProperties public const string BundleAssemblies = "BundleAssemblies"; public const string EnableProguard = "EnableProguard"; public const string AndroidEnableDesugar = "AndroidEnableDesugar"; + public const string AndroidUseR8 = "AndroidUseR8"; public const string UseJackAndJill = "UseJackAndJill"; public const string AotAssemblies = "AotAssemblies"; diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs index a3804b50f52..ee4643e518a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs @@ -85,6 +85,11 @@ public bool EnableDesugar { set { SetProperty (KnownProperties.AndroidEnableDesugar, value.ToString ()); } } + public bool UseR8 { + get { return string.Equals (GetProperty (KnownProperties.AndroidUseR8), "True", StringComparison.OrdinalIgnoreCase); } + set { SetProperty (KnownProperties.AndroidUseR8, value.ToString ()); } + } + public string AndroidFastDeploymentType { get { return GetProperty (KnownProperties.AndroidFastDeploymentType); } set { SetProperty (KnownProperties.AndroidFastDeploymentType, value); } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj index 89133632461..989ff459150 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj @@ -561,11 +561,13 @@ + + desugar_deploy.jar PreserveNewest @@ -710,6 +712,11 @@ proguard False + + {1bafa0cc-0377-46ce-ab7b-7bb2e7b62f63} + r8 + False + {E248B2CA-303B-4645-ADDC-9D4459D550FD} libZipSharp diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 80084f0bde8..08beeb346a8 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -70,6 +70,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. + @@ -277,6 +278,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. $(EnableProguard) False False + False 1G @@ -931,12 +933,36 @@ because xbuild doesn't support framework reference assemblies. /> + + + + + + + + + + + + + + + + @@ -2498,8 +2525,7 @@ because xbuild doesn't support framework reference assemblies. ProguardGeneratedApplicationConfiguration="$(IntermediateOutputPath)proguard\proguard_project_primary.cfg" ProguardConfigurationFiles="$(ProguardConfigFiles)" JavaLibrariesToEmbed="@(_JarsToProguard);@(_InstantRunJavaReference)" - ExternalJavaLibraries="@(AndroidExternalJavaLibrary)" - DoNotPackageJavaLibraries="@(_ResolvedDoNotPackageAttributes)" + JavaLibrariesToReference="@(AndroidExternalJavaLibrary)" ProguardJarOutput="$(IntermediateOutputPath)proguard\__proguard_output__.jar" EnableLogging="$(ProguardEnableLogging)" DumpOutput="$(IntermediateOutputPath)proguard\dump.txt" @@ -2557,8 +2583,66 @@ because xbuild doesn't support framework reference assemblies. + + + + + + + + + + + + + + + + + + + DependsOnTargets="_CompileToDalvikWithDx;_CompileToDalvikWithR8"> <_DexFile Include="$(IntermediateOutputPath)android\bin\dex\*.dex" /> diff --git a/src/r8/r8.csproj b/src/r8/r8.csproj new file mode 100644 index 00000000000..4756b644ec8 --- /dev/null +++ b/src/r8/r8.csproj @@ -0,0 +1,18 @@ + + + Debug + 1bafa0cc-0377-46ce-ab7b-7bb2e7b62f63 + Exe + bin\$(Configuration) + v2.0 + + + + + + + + + + + diff --git a/build-tools/r8/r8.props b/src/r8/r8.props similarity index 100% rename from build-tools/r8/r8.props rename to src/r8/r8.props diff --git a/build-tools/r8/r8.targets b/src/r8/r8.targets similarity index 94% rename from build-tools/r8/r8.targets rename to src/r8/r8.targets index adfb0c28cd5..f453fe8711b 100644 --- a/build-tools/r8/r8.targets +++ b/src/r8/r8.targets @@ -54,6 +54,11 @@ +