Skip to content

Commit e09ada7

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 f320507 commit e09ada7

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ Added in Xamarin.Android 10.3.
188188

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

191+
## AndroidBundleToolExtraArgs
192+
193+
Specifies additional
194+
command-line options to pass to the **bundletool** command when
195+
build app bundles.
196+
191197
## AndroidClassParser
192198

193199
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
@@ -2568,6 +2568,7 @@ because xbuild doesn't support framework reference assemblies.
25682568
KeyAlias="$(_ApkKeyAlias)"
25692569
KeyPass="$(_ApkKeyPass)"
25702570
StorePass="$(_ApkStorePass)"
2571+
ExtraArgs="$(AndroidBundleToolExtraArgs)"
25712572
/>
25722573
<InstallApkSet
25732574
ToolPath="$(JavaToolPath)"
@@ -2577,6 +2578,7 @@ because xbuild doesn't support framework reference assemblies.
25772578
AdbToolPath="$(AdbToolPath)"
25782579
AdbTarget="$(AdbTarget)"
25792580
ApkSet="$(_ApkSetIntermediate)"
2581+
Modules="@(AndroidInstallModules)"
25802582
/>
25812583
</Target>
25822584

0 commit comments

Comments
 (0)