From eef95d9c5df0e3b08043f8b4ab5c1da780bfd3cf Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 18 Dec 2020 17:03:55 +0100 Subject: [PATCH 1/8] [illink] Don't initialize managed peer Context: https://github.com/xamarin/xamarin-android/issues/5400 Context: https://github.com/xamarin/java.interop/pull/761 Generate `XAConfig.props` file in Java.Interop to define `XA_JI_EXCLUDE` compilation constant. The generated file contains properties set for Java.Interop by XA. So far it is only setting one property, and thus doesn't necessarily be generated. I still wanted to be written by `xaprep`, plus it might be handy in future for other configuration. The currently set `JavaInteropDefineConstants` property is going to be used to disable `ManagedPeer` initialization. We don't really use `ManagedPeer` today and it is duplicating functionality of `ConstructorBuilder` class. The unwanted effect of having it in JI is that it is pulling in System.Linq.Expressions, which greatly increase assemblies size after linking. The size reduction for simple XA app is cca 135kbytes of compressed size. Size difference in bytes ([*1] apk1 only, [*2] apk2 only): - 27 assemblies/Mono.Android.dll - 30 assemblies/System.Collections.Concurrent.dll - 989 assemblies/System.Linq.dll - 2,930 assemblies/Java.Interop.dll - 4,514 assemblies/System.Collections.dll *1 - 4,874 assemblies/System.ObjectModel.dll *1 - 7,987 assemblies/System.Private.CoreLib.dll - 115,284 assemblies/System.Linq.Expressions.dll *1 Summary: - 136,635 Assemblies -14.87% (of 918,689) - 139,506 Package size difference -1.79% (of 7,780,819) --- .../GeneratedJavaInteropConfigPropsFile.cs | 33 +++++++++++++++++++ .../xaprepare/Steps/Step_GenerateFiles.cs | 1 + 2 files changed, 34 insertions(+) create mode 100644 build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs diff --git a/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs new file mode 100644 index 00000000000..95c47ce8919 --- /dev/null +++ b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Xamarin.Android.Prepare +{ + class GeneratedJavaInteropConfigPropsFile : GeneratedFile + { + const string Content = @" + + + + + XA_JI_EXCLUDE + + +"; + + public GeneratedJavaInteropConfigPropsFile (Context context) + : base (Path.Combine (Configurables.Paths.ExternalJavaInteropDir, "bin", $"Build{context.Configuration}", "XAConfig.props")) + {} + + public override void Generate (Context context) + { + using (var fs = File.Open (OutputPath, FileMode.Create)) { + using (var sw = new StreamWriter (fs)) { + sw.Write (Content); + } + } + } + } +} diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs index 98649e3c6e7..a83a1ec51d1 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs @@ -66,6 +66,7 @@ protected override async Task Execute (Context context) var steps = new List { new GeneratedProfileAssembliesProjitemsFile (Configurables.Paths.ProfileAssembliesProjitemsPath), new GeneratedMonoAndroidProjitemsFile (), + new GeneratedJavaInteropConfigPropsFile (context), }; AddOSSpecificSteps (context, steps); From 04caadafdb2cd2fe31d7325a7c44b0707ed03878 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 18 Dec 2020 17:20:01 +0100 Subject: [PATCH 2/8] Update CheckIncludedAssemblies test --- .../Tests/Xamarin.Android.Build.Tests/PackagingTest.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs index 5afcf9b908f..15d5f56fa71 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs @@ -87,11 +87,8 @@ public void CheckIncludedAssemblies () "Java.Interop.dll", "Mono.Android.dll", "System.Console.dll", - "System.Linq.Expressions.dll", - "System.ObjectModel.dll", "System.Private.CoreLib.dll", "System.Collections.Concurrent.dll", - "System.Collections.dll", "System.Linq.dll", "UnnamedProject.dll", } : From 717ea164aff6b30c24611322b6975c1377a76218 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 18 Dec 2020 17:23:26 +0100 Subject: [PATCH 3/8] Cleaning --- .../Application/GeneratedJavaInteropConfigPropsFile.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs index 95c47ce8919..b3643c79ea9 100644 --- a/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs +++ b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; namespace Xamarin.Android.Prepare { From e683eda7bfe4c4fa18cd85a3648e043e2a126505 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 12 Jan 2021 11:57:01 +0100 Subject: [PATCH 4/8] Bump JI --- external/Java.Interop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Java.Interop b/external/Java.Interop index 3894cd76f71..a77aa3349ed 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit 3894cd76f71f618949c8542f0edd95762e22881f +Subproject commit a77aa3349eda9fec69dff9f0e105822acb5f28be From b53212210080c1bd097a90d4f6268846488d6cea Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 12 Jan 2021 15:13:00 +0100 Subject: [PATCH 5/8] Update the comment to contain link to the XA --- .../Application/GeneratedJavaInteropConfigPropsFile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs index b3643c79ea9..5e93eafce13 100644 --- a/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs +++ b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs @@ -6,7 +6,7 @@ class GeneratedJavaInteropConfigPropsFile : GeneratedFile { const string Content = @" - + XA_JI_EXCLUDE From c429ea9a04c15655685fa9ca05ec4d4dfe84d903 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 12 Jan 2021 16:39:58 +0100 Subject: [PATCH 6/8] Create the directory before writing file to it --- .../Application/GeneratedJavaInteropConfigPropsFile.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs index 5e93eafce13..c90f13d34ec 100644 --- a/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs +++ b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs @@ -20,6 +20,10 @@ public GeneratedJavaInteropConfigPropsFile (Context context) public override void Generate (Context context) { + string dir = Path.GetDirectoryName (OutputPath); + if (!Directory.Exists (dir)) + Directory.CreateDirectory (dir); + using (var fs = File.Open (OutputPath, FileMode.Create)) { using (var sw = new StreamWriter (fs)) { sw.Write (Content); From 85dd39cf5a5f6313e349855c6ac88faac6cc8a50 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Tue, 12 Jan 2021 16:41:54 +0100 Subject: [PATCH 7/8] Refactor --- .../Application/GeneratedJavaInteropConfigPropsFile.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs index c90f13d34ec..d32b4276508 100644 --- a/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs +++ b/build-tools/xaprepare/xaprepare/Application/GeneratedJavaInteropConfigPropsFile.cs @@ -20,15 +20,13 @@ public GeneratedJavaInteropConfigPropsFile (Context context) public override void Generate (Context context) { - string dir = Path.GetDirectoryName (OutputPath); + var dir = Path.GetDirectoryName (OutputPath); if (!Directory.Exists (dir)) Directory.CreateDirectory (dir); - using (var fs = File.Open (OutputPath, FileMode.Create)) { - using (var sw = new StreamWriter (fs)) { - sw.Write (Content); - } - } + using var fs = File.Open (OutputPath, FileMode.Create); + using var sw = new StreamWriter (fs); + sw.Write (Content); } } } From a04ba26b886c15976c6ec951da7c66e66740e6b2 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Fri, 15 Jan 2021 11:25:28 +0100 Subject: [PATCH 8/8] Bump JI --- external/Java.Interop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Java.Interop b/external/Java.Interop index a77aa3349ed..00862adaf1f 160000 --- a/external/Java.Interop +++ b/external/Java.Interop @@ -1 +1 @@ -Subproject commit a77aa3349eda9fec69dff9f0e105822acb5f28be +Subproject commit 00862adaf1f5447f2dcbff7b957083076da31a7b