-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R8 integration #1489
Closed
Closed
R8 integration #1489
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule depot_tools
added at
a16b4c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Condition=" '$(TpnIncludeExternalDependencies)' == 'True' "> | ||
<ThirdPartyNotice Include="google/depot_tools"> | ||
<LicenseFile>$(MSBuildThisFileDirectory)\depot_tools\LICENSE</LicenseFile> | ||
<SourceUrl>https://chromium.googlesource.com/chromium/tools/depot_tools.git</SourceUrl> | ||
</ThirdPartyNotice> | ||
</ItemGroup> | ||
</Project> |
Submodule r8
added at
d7c62c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup Condition=" '$(TpnIncludeExternalDependencies)' == 'True' "> | ||
<ThirdPartyNotice Include="google/r8"> | ||
<LicenseFile>$(MSBuildThisFileDirectory)\r8\LICENSE</LicenseFile> | ||
<SourceUrl>https://r8.googlesource.com/r8/</SourceUrl> | ||
</ThirdPartyNotice> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> (); | ||
var libjars = new List<string> (); | ||
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 (); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atsushieno this might depend on the platform, I seem to remember on windows vs Mac we had to use different enclosing chars. Might be worth double checking to be on the safe side. We've been bitten by this before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're kind of right, I saw the switch when the relevant files were passed in single argument in older proguard. I should simply use AppendSwitchIfNotNull() here.