From c533480e7c2d2860180dd5521882877d13b376fd Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 24 Nov 2020 13:09:26 +0000 Subject: [PATCH 1/3] [Xamarin.Android.Build.Tasks] Allow users to specify modules for apksets. Context #4810 When using app bundles users install the application from an `apkset`. At this time this only contains the base application. However we might in the future support dynamic features in some fashion. In this case developers should be able to pick which features they want installed. This commit adds an `AndroidInstallModules` ItemGroup which will allow developers to specify which modules to install. By default it will be empty. This means all modules which are to be installed on first install will be installed. So there is no change in the current behavior. This commit also adds support for passing additional arguments to `bundletool` via the new `$(AndroidBundleToolExtraArgs)` property. --- Documentation/guides/building-apps/build-items.md | 7 +++++++ .../guides/building-apps/build-properties.md | 6 ++++++ Documentation/release-notes/5327.md | 6 ++++++ src/Xamarin.Android.Build.Tasks/Tasks/BuildApkSet.cs | 6 +++++- .../Tasks/InstallApkSet.cs | 11 ++++++++--- .../Xamarin.Android.Common.targets | 2 ++ 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 Documentation/release-notes/5327.md diff --git a/Documentation/guides/building-apps/build-items.md b/Documentation/guides/building-apps/build-items.md index 7738de720d1..0e8f3c242f6 100644 --- a/Documentation/guides/building-apps/build-items.md +++ b/Documentation/guides/building-apps/build-items.md @@ -146,6 +146,13 @@ you can use the following to add this for a debug build. Introduced in Xamarin.Android 11.2 +## AndroidInstallModules + +Specifies the modules which get installed by **bundletool** command when +installing app bundles. + +Introduced in Xamarin.Android 11.3 + ## AndroidNativeLibrary [Native libraries](~/android/platform/native-libraries.md) diff --git a/Documentation/guides/building-apps/build-properties.md b/Documentation/guides/building-apps/build-properties.md index 4334facb935..ba8516be15c 100644 --- a/Documentation/guides/building-apps/build-properties.md +++ b/Documentation/guides/building-apps/build-properties.md @@ -198,6 +198,12 @@ Added in Xamarin.Android 10.3. [bundle-config-format]: https://developer.android.com/studio/build/building-cmdline#bundleconfig +## AndroidBundleToolExtraArgs + +Specifies additional +command-line options to pass to the **bundletool** command when +build app bundles. + ## AndroidClassParser A string property which controls how diff --git a/Documentation/release-notes/5327.md b/Documentation/release-notes/5327.md new file mode 100644 index 00000000000..a5171310801 --- /dev/null +++ b/Documentation/release-notes/5327.md @@ -0,0 +1,6 @@ +### Build and deployment performance + + * [GitHub PR 5327](https://github.com/xamarin/xamarin-android/pull/5327): + Allow users to specify additional app bundle "modules" when + building using `$(AndroidPackageFormat)` set to `aab`. In the + future this will help us support [Dynamic Features](https://developer.android.com/guide/app-bundle/play-feature-delivery) \ No newline at end of file diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApkSet.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApkSet.cs index 87b039a02cf..898c55661f7 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApkSet.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApkSet.cs @@ -8,7 +8,7 @@ namespace Xamarin.Android.Tasks { /// /// Invokes `bundletool` to create an APK set (.apks file) - /// + /// /// Usage: bundletool build-apks --bundle=foo.aab --output=foo.apks /// public class BuildApkSet : BundleToolAdbTask @@ -40,6 +40,8 @@ public class BuildApkSet : BundleToolAdbTask [Required] public string StorePass { get; set; } + public string ExtraArgs { get; set; } + public override bool RunTask () { //NOTE: bundletool will not overwrite @@ -77,6 +79,8 @@ internal override CommandLineBuilder GetCommandLineBuilder () cmd.AppendSwitchIfNotNull ("--ks-key-alias ", KeyAlias); AddStorePass (cmd, "--key-pass", KeyPass); AddStorePass (cmd, "--ks-pass", StorePass); + if (!string.IsNullOrEmpty (ExtraArgs)) + cmd.AppendSwitch (ExtraArgs); return cmd; } } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/InstallApkSet.cs b/src/Xamarin.Android.Build.Tasks/Tasks/InstallApkSet.cs index 67be8bdbb1e..022f8739f0c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/InstallApkSet.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/InstallApkSet.cs @@ -7,7 +7,7 @@ namespace Xamarin.Android.Tasks { /// /// Invokes `bundletool` to install an APK set to an attached device - /// + /// /// Usage: bundletool install-apks --apks=foo.apks /// public class InstallApkSet : BundleToolAdbTask @@ -17,6 +17,8 @@ public class InstallApkSet : BundleToolAdbTask [Required] public string ApkSet { get; set; } + public string[] Modules { get; set; } + internal override CommandLineBuilder GetCommandLineBuilder () { var cmd = base.GetCommandLineBuilder (); @@ -28,8 +30,11 @@ internal override CommandLineBuilder GetCommandLineBuilder () // --modules: List of modules to be installed, or "_ALL_" for all modules. // Defaults to modules installed during first install, i.e. not on-demand. // Xamarin.Android won't support on-demand modules yet. - cmd.AppendSwitchIfNotNull ("--modules ", "_ALL_"); - + if (Modules == null) + cmd.AppendSwitchIfNotNull ("--modules ", "_ALL_"); + else + cmd.AppendSwitchIfNotNull ("--modules ", $"\"{string.Join ("\",\"", Modules)}\""); + return cmd; } } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index f258f0338f5..a26210586be 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2513,6 +2513,7 @@ because xbuild doesn't support framework reference assemblies. KeyAlias="$(_ApkKeyAlias)" KeyPass="$(_ApkKeyPass)" StorePass="$(_ApkStorePass)" + ExtraArgs="$(AndroidBundleToolExtraArgs)" /> From 0de80260034a733525f72241b5a2720acbe3b81f Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 8 Mar 2021 20:12:53 -0500 Subject: [PATCH 2/3] update intro message --- Documentation/guides/building-apps/build-items.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/guides/building-apps/build-items.md b/Documentation/guides/building-apps/build-items.md index 0e8f3c242f6..26f8225f3d0 100644 --- a/Documentation/guides/building-apps/build-items.md +++ b/Documentation/guides/building-apps/build-items.md @@ -151,7 +151,7 @@ Introduced in Xamarin.Android 11.2 Specifies the modules which get installed by **bundletool** command when installing app bundles. -Introduced in Xamarin.Android 11.3 +This build action was introduced in Xamarin.Android 11.3. ## AndroidNativeLibrary From b324214a0197412ca7f9318e3762de394008fcf0 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 8 Mar 2021 20:13:37 -0500 Subject: [PATCH 3/3] Mention when AndroidBundleToolExtraArgs was added --- Documentation/guides/building-apps/build-properties.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/guides/building-apps/build-properties.md b/Documentation/guides/building-apps/build-properties.md index ba8516be15c..6dd3e44e111 100644 --- a/Documentation/guides/building-apps/build-properties.md +++ b/Documentation/guides/building-apps/build-properties.md @@ -204,6 +204,8 @@ Specifies additional command-line options to pass to the **bundletool** command when build app bundles. +This property was added in Xamarin.Android 11.3. + ## AndroidClassParser A string property which controls how