Skip to content

Commit c533480

Browse files
committed
[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.
1 parent dcd1cb7 commit c533480

File tree

6 files changed

+34
-4
lines changed

6 files changed

+34
-4
lines changed

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

+7
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
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+
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

+6
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ 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+
201207
## AndroidClassParser
202208

203209
A string property which controls how

Documentation/release-notes/5327.md

+6
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

+5-1
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

+8-3
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

+2
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,7 @@ because xbuild doesn't support framework reference assemblies.
25132513
KeyAlias="$(_ApkKeyAlias)"
25142514
KeyPass="$(_ApkKeyPass)"
25152515
StorePass="$(_ApkStorePass)"
2516+
ExtraArgs="$(AndroidBundleToolExtraArgs)"
25162517
/>
25172518
<InstallApkSet
25182519
ToolPath="$(JavaToolPath)"
@@ -2522,6 +2523,7 @@ because xbuild doesn't support framework reference assemblies.
25222523
AdbToolPath="$(AdbToolPath)"
25232524
AdbTarget="$(AdbTarget)"
25242525
ApkSet="$(_ApkSetIntermediate)"
2526+
Modules="@(AndroidInstallModules)"
25252527
/>
25262528
</Target>
25272529

0 commit comments

Comments
 (0)