Skip to content

Commit ee4b983

Browse files
authored
[Xamarin.Android.Build.Tasks] Add AndroidInstallModules for apksets (#5327)
Context: #4810 Context: #4810 (comment) Context: https://developer.android.com/guide/app-bundle/play-feature-delivery Android introduced support for using [Android App Bundles][0] to package features into separately downloadable [feature modules][1]. 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 feature modules 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, which means that all modules which are to be installed on first install will be installed. There will be no change to current behavior when `@(AndroidInstallModules)` is empty. Also add support for passing additional arguments to `bundletool` via the new `$(AndroidBundleToolExtraArgs)` property. [0]: https://developer.android.com/guide/app-bundle [1]: https://developer.android.com/guide/app-bundle/play-feature-delivery
1 parent 52bc127 commit ee4b983

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

Documentation/guides/building-apps/build-items.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ You can use the following to add this for a debug build:
146146

147147
This build action was introduced in Xamarin.Android 11.2.
148148

149+
## AndroidInstallModules
150+
151+
Specifies the modules which get installed by **bundletool** command when
152+
installing app bundles.
153+
154+
This build action was introduced in Xamarin.Android 11.3.
155+
149156
## AndroidNativeLibrary
150157

151158
[Native libraries](~/android/platform/native-libraries.md)

Documentation/guides/building-apps/build-properties.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ Added in Xamarin.Android 10.3.
198198

199199
[bundle-config-format]: https://developer.android.com/studio/build/building-cmdline#bundleconfig
200200

201+
## AndroidBundleToolExtraArgs
202+
203+
Specifies additional
204+
command-line options to pass to the **bundletool** command when
205+
build app bundles.
206+
207+
This property was added in Xamarin.Android 11.3.
208+
201209
## AndroidClassParser
202210

203211
A string property which controls how
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Build and deployment performance
2+
3+
* [GitHub PR 5327](https://github.com/xamarin/xamarin-android/pull/5327):
4+
Allow users to specify additional app bundle "modules" when
5+
building using `$(AndroidPackageFormat)` set to `aab`. In the
6+
future this will help us support [Dynamic Features](https://developer.android.com/guide/app-bundle/play-feature-delivery)

src/Xamarin.Android.Build.Tasks/Tasks/BuildApkSet.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Xamarin.Android.Tasks
88
{
99
/// <summary>
1010
/// Invokes `bundletool` to create an APK set (.apks file)
11-
///
11+
///
1212
/// Usage: bundletool build-apks --bundle=foo.aab --output=foo.apks
1313
/// </summary>
1414
public class BuildApkSet : BundleToolAdbTask
@@ -40,6 +40,8 @@ public class BuildApkSet : BundleToolAdbTask
4040
[Required]
4141
public string StorePass { get; set; }
4242

43+
public string ExtraArgs { get; set; }
44+
4345
public override bool RunTask ()
4446
{
4547
//NOTE: bundletool will not overwrite
@@ -77,6 +79,8 @@ internal override CommandLineBuilder GetCommandLineBuilder ()
7779
cmd.AppendSwitchIfNotNull ("--ks-key-alias ", KeyAlias);
7880
AddStorePass (cmd, "--key-pass", KeyPass);
7981
AddStorePass (cmd, "--ks-pass", StorePass);
82+
if (!string.IsNullOrEmpty (ExtraArgs))
83+
cmd.AppendSwitch (ExtraArgs);
8084
return cmd;
8185
}
8286
}

src/Xamarin.Android.Build.Tasks/Tasks/InstallApkSet.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Xamarin.Android.Tasks
77
{
88
/// <summary>
99
/// Invokes `bundletool` to install an APK set to an attached device
10-
///
10+
///
1111
/// Usage: bundletool install-apks --apks=foo.apks
1212
/// </summary>
1313
public class InstallApkSet : BundleToolAdbTask
@@ -17,6 +17,8 @@ public class InstallApkSet : BundleToolAdbTask
1717
[Required]
1818
public string ApkSet { get; set; }
1919

20+
public string[] Modules { get; set; }
21+
2022
internal override CommandLineBuilder GetCommandLineBuilder ()
2123
{
2224
var cmd = base.GetCommandLineBuilder ();
@@ -28,8 +30,11 @@ internal override CommandLineBuilder GetCommandLineBuilder ()
2830
// --modules: List of modules to be installed, or "_ALL_" for all modules.
2931
// Defaults to modules installed during first install, i.e. not on-demand.
3032
// Xamarin.Android won't support on-demand modules yet.
31-
cmd.AppendSwitchIfNotNull ("--modules ", "_ALL_");
32-
33+
if (Modules == null)
34+
cmd.AppendSwitchIfNotNull ("--modules ", "_ALL_");
35+
else
36+
cmd.AppendSwitchIfNotNull ("--modules ", $"\"{string.Join ("\",\"", Modules)}\"");
37+
3338
return cmd;
3439
}
3540
}

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,6 +2518,7 @@ because xbuild doesn't support framework reference assemblies.
25182518
KeyAlias="$(_ApkKeyAlias)"
25192519
KeyPass="$(_ApkKeyPass)"
25202520
StorePass="$(_ApkStorePass)"
2521+
ExtraArgs="$(AndroidBundleToolExtraArgs)"
25212522
/>
25222523
<InstallApkSet
25232524
ToolPath="$(JavaToolPath)"
@@ -2527,6 +2528,7 @@ because xbuild doesn't support framework reference assemblies.
25272528
AdbToolPath="$(AdbToolPath)"
25282529
AdbTarget="$(AdbTarget)"
25292530
ApkSet="$(_ApkSetIntermediate)"
2531+
Modules="@(AndroidInstallModules)"
25302532
/>
25312533
</Target>
25322534

0 commit comments

Comments
 (0)