Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Add AndroidInstallModules for apksets (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
dellis1972 authored Mar 9, 2021
1 parent 52bc127 commit ee4b983
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Documentation/guides/building-apps/build-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ You can use the following to add this for a debug build:

This build action was introduced in Xamarin.Android 11.2.

## AndroidInstallModules

Specifies the modules which get installed by **bundletool** command when
installing app bundles.

This build action was introduced in Xamarin.Android 11.3.

## AndroidNativeLibrary

[Native libraries](~/android/platform/native-libraries.md)
Expand Down
8 changes: 8 additions & 0 deletions Documentation/guides/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ 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.

This property was added in Xamarin.Android 11.3.

## AndroidClassParser

A string property which controls how
Expand Down
6 changes: 6 additions & 0 deletions Documentation/release-notes/5327.md
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 5 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/BuildApkSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Xamarin.Android.Tasks
{
/// <summary>
/// Invokes `bundletool` to create an APK set (.apks file)
///
///
/// Usage: bundletool build-apks --bundle=foo.aab --output=foo.apks
/// </summary>
public class BuildApkSet : BundleToolAdbTask
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/Xamarin.Android.Build.Tasks/Tasks/InstallApkSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Xamarin.Android.Tasks
{
/// <summary>
/// Invokes `bundletool` to install an APK set to an attached device
///
///
/// Usage: bundletool install-apks --apks=foo.apks
/// </summary>
public class InstallApkSet : BundleToolAdbTask
Expand All @@ -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 ();
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,7 @@ because xbuild doesn't support framework reference assemblies.
KeyAlias="$(_ApkKeyAlias)"
KeyPass="$(_ApkKeyPass)"
StorePass="$(_ApkStorePass)"
ExtraArgs="$(AndroidBundleToolExtraArgs)"
/>
<InstallApkSet
ToolPath="$(JavaToolPath)"
Expand All @@ -2527,6 +2528,7 @@ because xbuild doesn't support framework reference assemblies.
AdbToolPath="$(AdbToolPath)"
AdbTarget="$(AdbTarget)"
ApkSet="$(_ApkSetIntermediate)"
Modules="@(AndroidInstallModules)"
/>
</Target>

Expand Down

0 comments on commit ee4b983

Please sign in to comment.