Skip to content

Commit

Permalink
Prepare for release 1.14.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
sopo-c committed Jan 31, 2023
1 parent 9e554ac commit da6938b
Show file tree
Hide file tree
Showing 38 changed files with 1,705 additions and 188 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ https://developer.android.com/studio/command-line/bundletool

## Releases

Latest release: [1.13.2](https://github.com/google/bundletool/releases)
Latest release: [1.14.0](https://github.com/google/bundletool/releases)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version = 1.13.2
release_version = 1.14.0
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.android.tools.build.bundletool.commands.BuildApksCommand;
import com.android.tools.build.bundletool.commands.BuildBundleCommand;
import com.android.tools.build.bundletool.commands.BuildSdkApksCommand;
import com.android.tools.build.bundletool.commands.BuildSdkApksForAppCommand;
import com.android.tools.build.bundletool.commands.BuildSdkAsarCommand;
import com.android.tools.build.bundletool.commands.BuildSdkBundleCommand;
import com.android.tools.build.bundletool.commands.CheckTransparencyCommand;
Expand Down Expand Up @@ -88,6 +89,9 @@ static void main(String[] args, Runtime runtime) {
case BuildSdkApksCommand.COMMAND_NAME:
BuildSdkApksCommand.fromFlags(flags).execute();
break;
case BuildSdkApksForAppCommand.COMMAND_NAME:
BuildSdkApksForAppCommand.fromFlags(flags).execute();
break;
case BuildSdkAsarCommand.COMMAND_NAME:
BuildSdkAsarCommand.fromFlags(flags).execute();
break;
Expand Down Expand Up @@ -171,6 +175,7 @@ public static void help() {
BuildApksCommand.help(),
BuildSdkBundleCommand.help(),
BuildSdkApksCommand.help(),
BuildSdkApksForAppCommand.help(),
BuildSdkAsarCommand.help(),
PrintDeviceTargetingConfigCommand.help(),
EvaluateDeviceTargetingConfigCommand.help(),
Expand Down Expand Up @@ -206,6 +211,9 @@ public static void help(String commandName, Runtime runtime) {
case BuildSdkApksCommand.COMMAND_NAME:
commandHelp = BuildSdkApksCommand.help();
break;
case BuildSdkApksForAppCommand.COMMAND_NAME:
commandHelp = BuildSdkApksForAppCommand.help();
break;
case BuildSdkAsarCommand.COMMAND_NAME:
commandHelp = BuildSdkAsarCommand.help();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static com.android.tools.build.bundletool.model.AndroidManifest.MAIN_ACTION_NAME;
import static com.android.tools.build.bundletool.model.AndroidManifest.META_DATA_GMS_VERSION;
import static com.android.tools.build.bundletool.model.AndroidManifest.TOUCHSCREEN_FEATURE_NAME;
import static com.android.tools.build.bundletool.model.AndroidManifest.USES_FEATURE_HARDWARE_WATCH_NAME;
import static com.google.common.base.Preconditions.checkNotNull;

import com.android.tools.build.bundletool.model.AndroidManifest;
Expand All @@ -43,11 +44,13 @@
/** Utility methods for creation of archived manifest. */
public final class ArchivedAndroidManifestUtils {
public static final String META_DATA_KEY_ARCHIVED = "com.android.vending.archive";

public static final int WINDOW_IS_TRANSLUCENT_RESOURCE_ID = 0x01010058;
public static final int WINDOW_BACKGROUND_RESOURCE_ID = 0x01010054;
public static final int SCREEN_BACKGROUND_DARK_TRANSPARENT_THEME_RESOURCE_ID = 0x010800a9;
public static final int HOLO_LIGHT_NO_ACTION_BAR_FULSCREEN_THEME_RESOURCE_ID = 0x010300f1;
public static final int BACKGROUND_DIM_ENABLED = 0x0101021f;
public static final String REACTIVATE_ACTIVITY_NAME =
"com.google.android.archive.ReactivateActivity";
public static final int HOLO_LIGHT_NO_ACTION_BAR_FULSCREEN_THEME_RES_ID = 0x010300f1;

public static final String UPDATE_BROADCAST_RECEIVER_NAME =
"com.google.android.archive.UpdateBroadcastReceiver";
public static final String MY_PACKAGE_REPLACED_ACTION_NAME =
Expand Down Expand Up @@ -119,6 +122,11 @@ public static AndroidManifest createArchivedManifest(AndroidManifest manifest) {
.getMetadataElement(META_DATA_GMS_VERSION)
.ifPresent(editor::addApplicationChildElement);

// Make archived APK generated for wear AAB as a wear app
manifest
.getUsesFeatureElement(USES_FEATURE_HARDWARE_WATCH_NAME)
.forEach(editor::addManifestChildElement);

CHILDREN_ELEMENTS_TO_KEEP.forEach(
elementName -> editor.copyChildrenElements(manifest, elementName));

Expand All @@ -136,7 +144,7 @@ private static XmlProtoNode createMinimalManifestTag() {
.build());
}

public static AndroidManifest updateArchivedIcons(
public static AndroidManifest updateArchivedIconsAndTheme(
AndroidManifest manifest, ImmutableMap<String, Integer> resourceNameToIdMap) {
ManifestEditor archivedManifestEditor = manifest.toEditor();

Expand All @@ -151,6 +159,10 @@ public static AndroidManifest updateArchivedIcons(
resourceNameToIdMap.get(ARCHIVED_ROUND_ICON_DRAWABLE_NAME));
}

archivedManifestEditor.setActivityTheme(
REACTIVATE_ACTIVITY_NAME,
resourceNameToIdMap.getOrDefault(ArchivedResourcesHelper.ARCHIVED_TV_THEME_NAME, 0));

return archivedManifestEditor.save();
}

Expand All @@ -168,10 +180,11 @@ private static Activity createReactivateActivity(AndroidManifest manifest) {

return Activity.builder()
.setName(REACTIVATE_ACTIVITY_NAME)
.setTheme(HOLO_LIGHT_NO_ACTION_BAR_FULSCREEN_THEME_RES_ID)
.setTheme(HOLO_LIGHT_NO_ACTION_BAR_FULSCREEN_THEME_RESOURCE_ID)
.setExported(true)
.setExcludeFromRecents(true)
.setStateNotNeeded(true)
.setNoHistory(true)
.setIntentFilter(intentFilterBuilder.build())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.android.aapt.Resources.ResourceTable;
import com.android.tools.build.bundletool.commands.BuildApksModule.UpdateIconInArchiveMode;
import com.android.tools.build.bundletool.io.ResourceReader;
import com.android.tools.build.bundletool.model.AndroidManifest;
import com.android.tools.build.bundletool.model.AppBundle;
Expand Down Expand Up @@ -47,13 +46,11 @@
* resources and two custom actions to clear app cache and to wake up an app.
*/
public final class ArchivedApksGenerator {
private final boolean updateIconInArchiveMode;
private final ResourceReader resourceReader;
private final ArchivedResourcesHelper archivedResourcesHelper;

@Inject
ArchivedApksGenerator(@UpdateIconInArchiveMode boolean updateIconInArchiveMode) {
this.updateIconInArchiveMode = updateIconInArchiveMode;
ArchivedApksGenerator() {
resourceReader = new ResourceReader();
archivedResourcesHelper = new ArchivedResourcesHelper(resourceReader);
}
Expand All @@ -74,37 +71,23 @@ public ModuleSplit generateArchivedApk(
ResourceInjector resourceInjector =
new ResourceInjector(archivedResourceTable.toBuilder(), appBundle.getPackageName());

ImmutableMap<ZipPath, ByteSource> additionalResourcesByByteSource = ImmutableMap.of();
if (updateIconInArchiveMode) {
ImmutableMap<String, Integer> extraResourceNameToIdMap =
ArchivedResourcesHelper.injectExtraResources(
resourceInjector, customAppStorePackageName, iconAttribute, roundIconAttribute);

additionalResourcesByByteSource =
archivedResourcesHelper.buildAdditionalResourcesByByteSourceMap(
extraResourceNameToIdMap.get(ArchivedResourcesHelper.CLOUD_SYMBOL_DRAWABLE_NAME),
extraResourceNameToIdMap.get(ArchivedResourcesHelper.OPACITY_LAYER_DRAWABLE_NAME),
iconAttribute,
roundIconAttribute,
archivedResourcesHelper.findArchivedClassesDexPath(
appBundle.getVersion(),
BundleTransparencyCheckUtils.isTransparencyEnabled(appBundle)));

archivedManifest =
ArchivedAndroidManifestUtils.updateArchivedIcons(
archivedManifest, extraResourceNameToIdMap);
} else {
resourceInjector.addStringResource(
ArchivedResourcesHelper.APP_STORE_PACKAGE_NAME_RESOURCE_NAME,
ArchivedResourcesHelper.getAppStorePackageName(customAppStorePackageName));
additionalResourcesByByteSource =
ImmutableMap.of(
BundleModule.DEX_DIRECTORY.resolve("classes.dex"),
resourceReader.getResourceByteSource(
archivedResourcesHelper.findArchivedClassesDexPath(
appBundle.getVersion(),
BundleTransparencyCheckUtils.isTransparencyEnabled(appBundle))));
}
ImmutableMap<String, Integer> extraResourceNameToIdMap =
ArchivedResourcesHelper.injectExtraResources(
resourceInjector, customAppStorePackageName, iconAttribute, roundIconAttribute);

ImmutableMap<ZipPath, ByteSource> additionalResourcesByByteSource =
archivedResourcesHelper.buildAdditionalResourcesByByteSourceMap(
extraResourceNameToIdMap.get(ArchivedResourcesHelper.CLOUD_SYMBOL_DRAWABLE_NAME),
extraResourceNameToIdMap.get(ArchivedResourcesHelper.OPACITY_LAYER_DRAWABLE_NAME),
iconAttribute,
roundIconAttribute,
archivedResourcesHelper.findArchivedClassesDexPath(
appBundle.getVersion(),
BundleTransparencyCheckUtils.isTransparencyEnabled(appBundle)));

archivedManifest =
ArchivedAndroidManifestUtils.updateArchivedIconsAndTheme(
archivedManifest, extraResourceNameToIdMap);

ModuleSplit moduleSplit =
ModuleSplit.forArchive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@

package com.android.tools.build.bundletool.archive;

import static com.android.tools.build.bundletool.archive.ArchivedAndroidManifestUtils.BACKGROUND_DIM_ENABLED;
import static com.android.tools.build.bundletool.archive.ArchivedAndroidManifestUtils.HOLO_LIGHT_NO_ACTION_BAR_FULSCREEN_THEME_RESOURCE_ID;
import static com.android.tools.build.bundletool.archive.ArchivedAndroidManifestUtils.SCREEN_BACKGROUND_DARK_TRANSPARENT_THEME_RESOURCE_ID;
import static com.android.tools.build.bundletool.archive.ArchivedAndroidManifestUtils.WINDOW_BACKGROUND_RESOURCE_ID;
import static com.android.tools.build.bundletool.archive.ArchivedAndroidManifestUtils.WINDOW_IS_TRANSLUCENT_RESOURCE_ID;
import static com.android.tools.build.bundletool.model.AndroidManifest.ANDROID_NAMESPACE_URI;
import static com.android.tools.build.bundletool.model.AndroidManifest.DRAWABLE_RESOURCE_ID;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.Comparator.reverseOrder;

import com.android.aapt.Resources.Item;
import com.android.aapt.Resources.Primitive;
import com.android.aapt.Resources.Reference;
import com.android.aapt.Resources.Style;
import com.android.aapt.Resources.Style.Entry;
import com.android.tools.build.bundletool.io.ResourceReader;
import com.android.tools.build.bundletool.model.BundleModule;
import com.android.tools.build.bundletool.model.ResourceInjector;
Expand All @@ -39,6 +49,7 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.logging.Logger;

/** Helper methods for managing extra resources for archived apps. */
Expand All @@ -56,6 +67,7 @@ public final class ArchivedResourcesHelper {
"com_android_vending_archive_application_round_icon";
public static final String ARCHIVED_SPLASH_SCREEN_LAYOUT_NAME =
"com_android_vending_archive_splash_screen_layout";
public static final String ARCHIVED_TV_THEME_NAME = "com_android_vending_archive_tv_theme";

public static final String ARCHIVED_CLASSES_DEX_PATH_PREFIX =
"/com/android/tools/build/bundletool/archive/dex";
Expand Down Expand Up @@ -156,6 +168,11 @@ public static ImmutableMap<String, Integer> injectExtraResources(
BundleModule.DRAWABLE_RESOURCE_DIRECTORY
.resolve(String.format("%s.xml", CLOUD_SYMBOL_DRAWABLE_NAME))
.toString())
.getFullResourceId())
.put(
ARCHIVED_TV_THEME_NAME,
resourceInjector
.addStyleResource(ARCHIVED_TV_THEME_NAME, buildArchivedTvActivityTheme())
.getFullResourceId());
iconAttribute.ifPresent(
attribute -> {
Expand Down Expand Up @@ -283,6 +300,38 @@ private static XmlProtoNode buildFrameLayoutXmlNode(int imageResId) {
.asXmlProtoElement());
}

private static Style buildArchivedTvActivityTheme() {
return Style.newBuilder()
.setParent(
Reference.newBuilder().setId(HOLO_LIGHT_NO_ACTION_BAR_FULSCREEN_THEME_RESOURCE_ID))
// To make the background of the activity transparent.
.addEntry(
createStyleEntryBuilder(
WINDOW_IS_TRANSLUCENT_RESOURCE_ID,
item -> item.setPrim(Primitive.newBuilder().setBooleanValue(true))))
// A black background.
.addEntry(
createStyleEntryBuilder(
WINDOW_BACKGROUND_RESOURCE_ID,
item ->
item.setRef(
Reference.newBuilder()
.setId(SCREEN_BACKGROUND_DARK_TRANSPARENT_THEME_RESOURCE_ID))))
// Add a dimmed effect to background.
.addEntry(
createStyleEntryBuilder(
BACKGROUND_DIM_ENABLED,
item -> item.setPrim(Primitive.newBuilder().setBooleanValue(true))))
.build();
}

private static Entry.Builder createStyleEntryBuilder(
int resourceId, Consumer<Item.Builder> itemConsumer) {
Item.Builder itemBuilder = Item.newBuilder();
itemConsumer.accept(itemBuilder);
return Entry.newBuilder().setKey(Reference.newBuilder().setId(resourceId)).setItem(itemBuilder);
}

private static XmlProtoAttributeBuilder createDrawableAttribute(int referenceId) {
return XmlProtoAttributeBuilder.create("drawable")
.setResourceId(DRAWABLE_RESOURCE_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ ListeningExecutorService getExecutorService() {

public abstract Optional<String> getAppStorePackageName();

public abstract boolean getEnableBaseModuleMinSdkAsDefaultTargeting();

public static Builder builder() {
return new AutoValue_BuildApksCommand.Builder()
.setOverwriteOutput(false)
Expand All @@ -326,7 +328,8 @@ public static Builder builder() {
.setSystemApkOptions(ImmutableSet.of())
.setEnableApkSerializerWithoutBundleRecompression(true)
.setRuntimeEnabledSdkBundlePaths(ImmutableSet.of())
.setRuntimeEnabledSdkArchivePaths(ImmutableSet.of());
.setRuntimeEnabledSdkArchivePaths(ImmutableSet.of())
.setEnableBaseModuleMinSdkAsDefaultTargeting(false);
}

/** Builder for the {@link BuildApksCommand}. */
Expand Down Expand Up @@ -573,6 +576,12 @@ public abstract Builder setLocalDeploymentRuntimeEnabledSdkConfig(
*/
public abstract Builder setAppStorePackageName(String appStorePackageName);

/**
* If true, will set default min sdk version targeting for generated splits as min sdk of base
* module.
*/
public abstract Builder setEnableBaseModuleMinSdkAsDefaultTargeting(boolean value);

abstract BuildApksCommand autoBuild();

public BuildApksCommand build() {
Expand Down Expand Up @@ -993,13 +1002,7 @@ private ImmutableMap<String, BundleModule> getValidatedSdkModules(
ImmutableMap<String, SdkAsar> sdkAsars = getValidatedSdkAsarsByPackageName(closer, tempDir);
validateSdkAsarsMatchAppBundleDependencies(appBundle, sdkAsars);
return sdkAsars.entrySet().stream()
.collect(
toImmutableMap(
Entry::getKey,
entry ->
entry.getValue().getModule().toBuilder()
.setSdkModulesConfig(entry.getValue().getSdkModulesConfig())
.build()));
.collect(toImmutableMap(Entry::getKey, entry -> entry.getValue().getModule()));
}
ImmutableMap<String, SdkBundle> sdkBundles =
getValidatedSdkBundlesByPackageName(closer, tempDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ private ApkGenerationConfiguration.Builder getCommonSplitApkGenerationConfigurat

apkGenerationConfiguration.setSuffixStrippings(apkOptimizations.getSuffixStrippings());

apkGenerationConfiguration.setEnableBaseModuleMinSdkAsDefaultTargeting(
command.getEnableBaseModuleMinSdkAsDefaultTargeting());

command
.getMinSdkForAdditionalVariantWithV3Rotation()
.ifPresent(apkGenerationConfiguration::setMinSdkForAdditionalVariantWithV3Rotation);
Expand All @@ -360,6 +363,8 @@ private ApkGenerationConfiguration.Builder getCommonSplitApkGenerationConfigurat

private ApkGenerationConfiguration getAssetSliceGenerationConfiguration() {
return ApkGenerationConfiguration.builder()
.setEnableBaseModuleMinSdkAsDefaultTargeting(
command.getEnableBaseModuleMinSdkAsDefaultTargeting())
.setOptimizationDimensions(apkOptimizations.getSplitDimensionsForAssetModules())
.setSuffixStrippings(apkOptimizations.getSuffixStrippings())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,6 @@ static Optional<PrintStream> provideOutputPrintStream(BuildApksCommand command)
return command.getOutputPrintStream();
}

@CommandScoped
@Provides
@UpdateIconInArchiveMode
static boolean provideUpdateIconInArchiveMode(BuildApksCommand command) {
@SuppressWarnings("unused")
boolean updateIconInArchiveMode = false;
return updateIconInArchiveMode;
}

@CommandScoped
@Provides
static Optional<DeviceSpec> provideDeviceSpec(BuildApksCommand command) {
Expand Down Expand Up @@ -207,10 +198,5 @@ static Optional<LocalDeploymentRuntimeEnabledSdkConfig> provideLocalRuntimeEnabl
@Retention(RUNTIME)
public @interface ApkSigningConfigProvider {}

/** Qualifying annotation a {@code boolean} on whether to update archived apps icon. */
@Qualifier
@Retention(RUNTIME)
public @interface UpdateIconInArchiveMode {}

private BuildApksModule() {}
}
Loading

0 comments on commit da6938b

Please sign in to comment.