From 12756edd4b18bad62ae0d94cb745bfaca946d5c9 Mon Sep 17 00:00:00 2001 From: eric liu Date: Fri, 7 Sep 2018 17:37:09 +0200 Subject: [PATCH 1/7] Added --classpath_entry for Desugar --- src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs index fb3ee4e624a..79e30400513 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs @@ -85,6 +85,8 @@ protected override string GenerateCommandLineCommands () foreach (var jar in InputJars) { var output = Path.Combine (OutputDirectory, BitConverter.ToString (md5.ComputeHash (Encoding.UTF8.GetBytes (jar))) + Path.GetFileName (jar)); outputs.Add (output); + cmd.AppendSwitch ("--classpath_entry "); + cmd.AppendFileNameIfNotNull (jar); cmd.AppendSwitch ("--input "); cmd.AppendFileNameIfNotNull (jar); cmd.AppendSwitch ("--output "); From 2d1e06f3fe60690bf46ed8b6c13227635ad75a19 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Mon, 10 Sep 2018 14:30:02 -0500 Subject: [PATCH 2/7] [tests] reproduced issue with desugar To get some better testing here, I wrote a test that: - Uses the Twitter AAR file from maven central - Lots of dependencies for Twitter's SDK - Added proguard rules where needed - Requires `android:minSdkVersion="24"` for using these libraries --- .../Xamarin.Android.Build.Tests/BuildTest.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) 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 aaa387da0fc..da30709e696 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 @@ -2973,6 +2973,42 @@ public void Desugar (bool isRelease, bool enableDesugar, bool enableProguard) EnableDesugar = enableDesugar, EnableProguard = enableProguard, }; + proj.AndroidManifest = proj.AndroidManifest.Replace ("", ""); + //Okhttp and Okio + //https://github.com/square/okhttp + //https://github.com/square/okio + if (enableProguard) { + //NOTE: these are just enough rules to get it to build, not optimal + var rules = new [] { + "-dontwarn javax.annotation.**", + "-dontwarn org.codehaus.mojo.animal_sniffer.*", + }; + //FIXME: We aren't de-BOM'ing proguard files? + var encoding = new UTF8Encoding (encoderShouldEmitUTF8Identifier: false); + var bytes = encoding.GetBytes (string.Join (Environment.NewLine, rules)); + proj.OtherBuildItems.Add (new BuildItem ("ProguardConfiguration", "okhttp3.pro") { + BinaryContent = () => bytes, + }); + } + proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "okio-1.13.0.jar") { + WebContent = "http://central.maven.org/maven2/com/squareup/okio/okio/1.13.0/okio-1.13.0.jar" + }); + proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "okhttp-3.8.0.jar") { + WebContent = "http://central.maven.org/maven2/com/squareup/okhttp3/okhttp/3.8.0/okhttp-3.8.0.jar" + }); + proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "retrofit-2.3.0.jar") { + WebContent = "http://central.maven.org/maven2/com/squareup/retrofit2/retrofit/2.3.0/retrofit-2.3.0.jar" + }); + proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "converter-gson-2.3.0.jar") { + WebContent = "http://central.maven.org/maven2/com/squareup/retrofit2/converter-gson/2.3.0/converter-gson-2.3.0.jar" + }); + proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "gson-2.7.jar") { + WebContent = "http://central.maven.org/maven2/com/google/code/gson/gson/2.7/gson-2.7.jar" + }); + //Twitter SDK https://mvnrepository.com/artifact/com.twitter.sdk.android/twitter-core/3.3.0 + proj.OtherBuildItems.Add (new BuildItem ("AndroidAarLibrary", "twitter-core-3.3.0.aar") { + WebContent = "http://repo.spring.io/libs-release/com/twitter/sdk/android/twitter-core/3.3.0/twitter-core-3.3.0.aar", + }); /* The source is simple: * public class Lambda From 3ece5989cef2b7eebf622a7f52f236fd3622a68e Mon Sep 17 00:00:00 2001 From: eric liu Date: Wed, 12 Sep 2018 01:23:48 +0200 Subject: [PATCH 3/7] Update Desugar.cs under API 24 pass `--desugar_try_with_resources_omit_runtime_classes` --- src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs index 79e30400513..ec35dcbcf0a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs @@ -74,6 +74,10 @@ protected override string GenerateCommandLineCommands () cmd.AppendSwitch ("--min_sdk_version "); cmd.AppendSwitch (minApiVersion.ToString ()); + + if(minApiVersion < 24) { + commandLineBuilder.AppendSwitch("--desugar_try_with_resources_omit_runtime_classes "); + } //cmd.AppendSwitchIfNotNull ("-J-Dfile.encoding=", "UTF8"); From 769ac5380c782506d4da87e9b04976755498d59a Mon Sep 17 00:00:00 2001 From: eric liu Date: Wed, 12 Sep 2018 01:28:21 +0200 Subject: [PATCH 4/7] Update BuildTest.cs DesugarChecks should build now under api 24 --- .../Tests/Xamarin.Android.Build.Tests/BuildTest.cs | 1 - 1 file changed, 1 deletion(-) 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 da30709e696..7a7c93fb7f0 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 @@ -2973,7 +2973,6 @@ public void Desugar (bool isRelease, bool enableDesugar, bool enableProguard) EnableDesugar = enableDesugar, EnableProguard = enableProguard, }; - proj.AndroidManifest = proj.AndroidManifest.Replace ("", ""); //Okhttp and Okio //https://github.com/square/okhttp //https://github.com/square/okio From a04db8d46b413f5c3687ec0c0d050340012f20d6 Mon Sep 17 00:00:00 2001 From: eric liu Date: Wed, 12 Sep 2018 07:39:27 +0200 Subject: [PATCH 5/7] Update Desugar.cs ops I copied wrong line --- src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs index ec35dcbcf0a..28fde055a41 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs @@ -76,7 +76,7 @@ protected override string GenerateCommandLineCommands () cmd.AppendSwitch (minApiVersion.ToString ()); if(minApiVersion < 24) { - commandLineBuilder.AppendSwitch("--desugar_try_with_resources_omit_runtime_classes "); + cmd.AppendSwitch("--desugar_try_with_resources_omit_runtime_classes "); } //cmd.AppendSwitchIfNotNull ("-J-Dfile.encoding=", "UTF8"); From c3cb04d8ec3c7d939ee2ad48aa3527d8c4fd036b Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Fri, 14 Sep 2018 07:37:25 -0500 Subject: [PATCH 6/7] Code formatting --- src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs index 28fde055a41..918d6f7664e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Desugar.cs @@ -75,7 +75,7 @@ protected override string GenerateCommandLineCommands () cmd.AppendSwitch ("--min_sdk_version "); cmd.AppendSwitch (minApiVersion.ToString ()); - if(minApiVersion < 24) { + if (minApiVersion < 24) { cmd.AppendSwitch("--desugar_try_with_resources_omit_runtime_classes "); } From 96baa45771d14a6ccf0f108a958541170f845de7 Mon Sep 17 00:00:00 2001 From: eric liu Date: Tue, 18 Sep 2018 19:01:05 +0200 Subject: [PATCH 7/7] Update BuildTest.cs Ignore ProGuard `can't find referenced class com.google.devtools.build.android.desugar...`. --- .../Tests/Xamarin.Android.Build.Tests/BuildTest.cs | 1 + 1 file changed, 1 insertion(+) 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 7a7c93fb7f0..51557784f05 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 @@ -2979,6 +2979,7 @@ public void Desugar (bool isRelease, bool enableDesugar, bool enableProguard) if (enableProguard) { //NOTE: these are just enough rules to get it to build, not optimal var rules = new [] { + "-dontwarn com.google.devtools.build.android.desugar.**", "-dontwarn javax.annotation.**", "-dontwarn org.codehaus.mojo.animal_sniffer.*", };