Skip to content

Commit

Permalink
Prepare for release 1.15.6.
Browse files Browse the repository at this point in the history
  • Loading branch information
sopo-c committed Nov 7, 2023
1 parent 6b51fd7 commit 0b00e4a
Show file tree
Hide file tree
Showing 21 changed files with 254 additions and 93 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.15.5](https://github.com/google/bundletool/releases)
Latest release: [1.15.6](https://github.com/google/bundletool/releases)
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ test {
}

reports {
html.enabled = false
html {
enabled false
}
}
}

Expand Down Expand Up @@ -175,8 +177,8 @@ publishing {

// Artifact released to Maven.
shadowJar {
baseName = 'bundletool'
classifier = ''
archiveBaseName = 'bundletool'
archiveClassifier = ''

// Package all the Android Gradle plugin dependencies that are compiled from
// source.
Expand Down Expand Up @@ -211,8 +213,8 @@ shadowJar {

// Artifact to use as standalone command line tool.
task executableJar(type: ShadowJar) {
baseName = 'bundletool'
classifier = 'all'
archiveBaseName = 'bundletool'
archiveClassifier = 'all'
from sourceSets.main.output
from({ zipTree(project.configurations.implementationWindows.singleFile) }) { into 'windows/' }
from({ zipTree(project.configurations.implementationMacOs.singleFile) }) { into 'macos/' }
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version = 1.15.5
release_version = 1.15.6
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import com.android.tools.build.bundletool.model.manifestelements.Activity;
import com.android.tools.build.bundletool.model.manifestelements.IntentFilter;
import com.android.tools.build.bundletool.model.manifestelements.Receiver;
import com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttribute;
import com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder;
import com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNode;
import com.android.tools.build.bundletool.model.version.BundleToolVersion;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.Optional;

/** Utility methods for creation of archived manifest. */
public final class ArchivedAndroidManifestUtils {
Expand Down Expand Up @@ -91,7 +93,7 @@ public final class ArchivedAndroidManifestUtils {
AndroidManifest.PERMISSION_TREE_ELEMENT_NAME);

public static AndroidManifest createArchivedManifest(
AndroidManifest manifest, boolean createDifferentThemesForTvAndPhone) {
AndroidManifest manifest, boolean removeTvIconCloud) {
checkNotNull(manifest);

ManifestEditor editor =
Expand Down Expand Up @@ -131,7 +133,7 @@ public static AndroidManifest createArchivedManifest(
CHILDREN_ELEMENTS_TO_KEEP.forEach(
elementName -> editor.copyChildrenElements(manifest, elementName));

if (createDifferentThemesForTvAndPhone) {
if (removeTvIconCloud) {
if (manifest.hasMainActivity()) {
editor.addActivity(
createReactivateActivity(
Expand All @@ -146,7 +148,9 @@ public static AndroidManifest createArchivedManifest(
IntentFilter.builder()
.addActionName(MAIN_ACTION_NAME)
.addCategoryName(LEANBACK_LAUNCHER_CATEGORY_NAME)
.build()));
.build(),
manifest.getIconAttribute().map(XmlProtoAttribute::getValueAsRefId),
manifest.getRoundIconAttribute().map(XmlProtoAttribute::getValueAsRefId)));
}
} else {
editor.addActivity(createReactivateActivity(manifest));
Expand All @@ -168,7 +172,7 @@ private static XmlProtoNode createMinimalManifestTag() {
public static AndroidManifest updateArchivedIconsAndTheme(
AndroidManifest manifest,
ImmutableMap<String, Integer> resourceNameToIdMap,
boolean createDifferentThemesForTvAndPhone) {
boolean removeTvIconCloud) {
ManifestEditor archivedManifestEditor = manifest.toEditor();

if (manifest.getIconAttribute().isPresent()
Expand All @@ -182,20 +186,9 @@ public static AndroidManifest updateArchivedIconsAndTheme(
resourceNameToIdMap.get(ARCHIVED_ROUND_ICON_DRAWABLE_NAME));
}

if (createDifferentThemesForTvAndPhone) {
if (manifest.hasMainActivity()) {
archivedManifestEditor.setActivityTheme(
REACTIVATE_ACTIVITY_NAME,
LAUNCHER_CATEGORY_NAME,
HOLO_LIGHT_NO_ACTION_BAR_FULSCREEN_THEME_RESOURCE_ID);
}
if (manifest.hasMainTvActivity()) {
archivedManifestEditor.setActivityTheme(
REACTIVATE_ACTIVITY_NAME,
LEANBACK_LAUNCHER_CATEGORY_NAME,
checkNotNull(resourceNameToIdMap.get(ArchivedResourcesHelper.ARCHIVED_TV_THEME_NAME))
.intValue());
}
if (removeTvIconCloud) {
archivedManifestEditor.setApplicationTheme(
resourceNameToIdMap.get(ArchivedResourcesHelper.ARCHIVED_TV_THEME_NAME));
} else {
archivedManifestEditor.setActivityTheme(
REACTIVATE_ACTIVITY_NAME,
Expand All @@ -205,17 +198,21 @@ public static AndroidManifest updateArchivedIconsAndTheme(
return archivedManifestEditor.save();
}

private static Activity createReactivateActivity(IntentFilter intentFilter) {
return Activity.builder()

private static Activity createReactivateActivity(
IntentFilter intentFilter, Optional<Integer> icon, Optional<Integer> roundIcon) {
return getCommonActivityBuilder()
.setName(REACTIVATE_ACTIVITY_NAME)
.setExported(true)
.setExcludeFromRecents(true)
.setStateNotNeeded(true)
.setNoHistory(true)
.setIntentFilter(intentFilter)
.setIcon(icon)
.setRoundIcon(roundIcon)
.build();
}

private static Activity createReactivateActivity(IntentFilter intentFilter) {
return getCommonActivityBuilder().setIntentFilter(intentFilter).build();
}

private static Activity createReactivateActivity(AndroidManifest manifest) {
IntentFilter.Builder intentFilterBuilder =
IntentFilter.builder().addActionName(MAIN_ACTION_NAME);
Expand All @@ -239,6 +236,15 @@ private static Activity createReactivateActivity(AndroidManifest manifest) {
.build();
}

private static Activity.Builder getCommonActivityBuilder() {
return Activity.builder()
.setName(REACTIVATE_ACTIVITY_NAME)
.setExported(true)
.setExcludeFromRecents(true)
.setStateNotNeeded(true)
.setNoHistory(true);
}

private static Receiver createUpdateBroadcastReceiver() {
return Receiver.builder()
.setName(UPDATE_BROADCAST_RECEIVER_NAME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static com.google.common.base.Preconditions.checkNotNull;

import com.android.aapt.Resources.ResourceTable;
import com.android.tools.build.bundletool.commands.BuildApksModule.DifferentThemesForTvAndPhone;
import com.android.tools.build.bundletool.commands.BuildApksModule.RemoveTvIconCloud;
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 @@ -49,13 +49,13 @@
public final class ArchivedApksGenerator {
private final ResourceReader resourceReader;
private final ArchivedResourcesHelper archivedResourcesHelper;
private final boolean createDifferentThemesForTvAndPhone;
private final boolean removeTvIconCloud;

@Inject
ArchivedApksGenerator(@DifferentThemesForTvAndPhone boolean createDifferentThemesForTvAndPhone) {
ArchivedApksGenerator(@RemoveTvIconCloud boolean removeTvIconCloud) {
resourceReader = new ResourceReader();
archivedResourcesHelper = new ArchivedResourcesHelper(resourceReader);
this.createDifferentThemesForTvAndPhone = createDifferentThemesForTvAndPhone;
this.removeTvIconCloud = removeTvIconCloud;
}

public ModuleSplit generateArchivedApk(
Expand All @@ -66,7 +66,7 @@ public ModuleSplit generateArchivedApk(

AndroidManifest archivedManifest =
ArchivedAndroidManifestUtils.createArchivedManifest(
baseModule.getAndroidManifest(), createDifferentThemesForTvAndPhone);
baseModule.getAndroidManifest(), removeTvIconCloud);
ResourceTable archivedResourceTable =
getArchivedResourceTable(appBundle, baseModule, archivedManifest);

Expand All @@ -91,7 +91,7 @@ public ModuleSplit generateArchivedApk(

archivedManifest =
ArchivedAndroidManifestUtils.updateArchivedIconsAndTheme(
archivedManifest, extraResourceNameToIdMap, createDifferentThemesForTvAndPhone);
archivedManifest, extraResourceNameToIdMap, removeTvIconCloud);

ModuleSplit moduleSplit =
ModuleSplit.forArchive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ static Optional<LocalDeploymentRuntimeEnabledSdkConfig> provideLocalRuntimeEnabl

@CommandScoped
@Provides
@DifferentThemesForTvAndPhone
static boolean provideDifferentThemesForTvAndPhone(BuildApksCommand command) {
@RemoveTvIconCloud
static boolean provideRemoveTvIconCloud(BuildApksCommand command) {
@SuppressWarnings("unused")
boolean differentThemesForTvAndPhone = false;
return differentThemesForTvAndPhone;
boolean removeTvIconCloud = false;
return removeTvIconCloud;
}

/**
Expand Down Expand Up @@ -207,13 +207,10 @@ static boolean provideDifferentThemesForTvAndPhone(BuildApksCommand command) {
@Retention(RUNTIME)
public @interface ApkSigningConfigProvider {}

/**
* Qualifying annotation of a {@code boolean} to enable usage of different themes for tv and
* phone.
*/
/** Qualifying annotation of a {@code boolean} to enable removing the icon's cloud for TV. */
@Qualifier
@Retention(RUNTIME)
public @interface DifferentThemesForTvAndPhone {}
public @interface RemoveTvIconCloud {}

private BuildApksModule() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ ListeningExecutorService getExecutorService() {
public abstract Optional<Integer> getFirstVariantNumber();


public abstract Optional<Integer> getMinSdkVersion();

/** Creates a builder for the {@link BuildSdkApksCommand} with some default settings. */
public static BuildSdkApksCommand.Builder builder() {
return new AutoValue_BuildSdkApksCommand.Builder()
Expand All @@ -136,6 +138,8 @@ public static BuildSdkApksCommand.Builder builder() {
.setVerbose(false);
}

public abstract Builder toBuilder();

/** Builder for the {@link BuildSdkApksCommand}. */
@AutoValue.Builder
public abstract static class Builder {
Expand Down Expand Up @@ -231,6 +235,9 @@ public Builder setExecutorService(ListeningExecutorService executorService) {
public abstract Builder setFirstVariantNumber(int firstVariantNumber);


/** Overrides value of android:minSdkVersion attribute in the generated APKs. */
public abstract Builder setMinSdkVersion(int minSdkVersion);

abstract BuildSdkApksCommand autoBuild();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private ImmutableList<ModuleSplit> generateSdkApks() {
moduleSplit.writeSdkLibraryElement(
sdkBundle.getPackageName(), sdkBundle.getSdkAndroidVersionMajor()))
.map(ModuleSplit::overrideMinSdkVersionForSdkSandbox)
.map(moduleSplit -> overrideMinSdkVersion(moduleSplit))
.map(moduleSplit -> moduleSplit.writePatchVersion(sdkBundle.getPatchVersion()))
.map(moduleSplit -> moduleSplit.writeSdkProviderClassName(sdkBundle.getProviderClassName()))
.map(this::writeCompatSdkProviderClassNameIfPresent)
Expand All @@ -107,6 +108,12 @@ private ImmutableList<ModuleSplit> generateSdkApks() {
.collect(toImmutableList());
}

private ModuleSplit overrideMinSdkVersion(ModuleSplit moduleSplit) {
return command.getMinSdkVersion().isPresent()
? moduleSplit.overrideMinSdkVersion(command.getMinSdkVersion().get())
: moduleSplit.overrideMinSdkVersionForSdkSandbox();
}

private ModuleSplit writeCompatSdkProviderClassNameIfPresent(ModuleSplit moduleSplit) {
if (sdkBundle.getCompatProviderClassName().isPresent()) {
return moduleSplit.writeCompatSdkProviderClassName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class ModuleSplitSerializer extends ApkSerializer {
private final ListeningExecutorService executorService;
private final boolean use7ZipCompression;
private final Optional<P7ZipCommand> p7ZipCommand;
private final int nativeLibraryAlignment;

@Inject
ModuleSplitSerializer(
Expand Down Expand Up @@ -97,6 +98,7 @@ public class ModuleSplitSerializer extends ApkSerializer {
this.bundletoolVersion = bundletoolVersion;
this.executorService = executorService;
this.p7ZipCommand = p7ZipCommand;
this.nativeLibraryAlignment = getNativeLibraryAlignment(bundleConfig);
}

/**
Expand All @@ -105,6 +107,7 @@ public class ModuleSplitSerializer extends ApkSerializer {
* <p>Returns {@link ApkDescription} for each serialized split keyed by relative path of module
* split.
*/
@Override
public ImmutableMap<ZipPath, ApkDescription> serialize(
Path outputDirectory, ImmutableMap<ZipPath, ModuleSplit> splitsByRelativePath) {
// Prepare original splits by:
Expand Down Expand Up @@ -301,12 +304,13 @@ private void serializeSplit(
* <p>Uncompressed native libraries inside APK must be aligned by 4096 and all other uncompressed
* entries aligned by 4 bytes.
*/
private static long alignmentForEntry(
ModuleEntry entry, ModuleEntriesPack uncompressedEntriesPack) {
private long alignmentForEntry(ModuleEntry entry, ModuleEntriesPack uncompressedEntriesPack) {
if (!uncompressedEntriesPack.hasEntry(entry)) {
return 0;
}
return entry.getPath().toString().endsWith(NATIVE_LIBRARIES_SUFFIX) ? 4096 : 4;
return entry.getPath().toString().endsWith(NATIVE_LIBRARIES_SUFFIX)
? nativeLibraryAlignment
: 4;
}

/**
Expand Down Expand Up @@ -408,4 +412,18 @@ private boolean shouldUncompressBecauseOfLowRatio(
}
return compressedSize >= uncompressedSize;
}

private int getNativeLibraryAlignment(BundleConfig bundleConfig) {
switch (bundleConfig.getOptimizations().getUncompressNativeLibraries().getAlignment()) {
case PAGE_ALIGNMENT_16K:
return 16384;
case PAGE_ALIGNMENT_64K:
return 65536;
case PAGE_ALIGNMENT_UNSPECIFIED:
case PAGE_ALIGNMENT_4K:
case UNRECOGNIZED:
return 4096;
}
throw new IllegalArgumentException("Wrong native libraries alignment.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,15 @@ public ManifestEditor setActivityTheme(String activityName, int themeResId) {
return this;
}

@CanIgnoreReturnValue
public ManifestEditor setApplicationTheme(int themeResId) {
manifestElement
.getOrCreateChildElement(APPLICATION_ELEMENT_NAME)
.getOrCreateAndroidAttribute(THEME_ATTRIBUTE_NAME, THEME_RESOURCE_ID)
.setValueAsRefId(themeResId);
return this;
}

/**
* Sets the theme of an activity that has an action with the name mainActionCategoryName to the
* given themeResId. This method assumes such activity exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ public ModuleSplit overrideMinSdkVersionForSdkSandbox() {
return this;
}

/** Overrides value of android:minSdkVersion attribute in the manifest. */
public ModuleSplit overrideMinSdkVersion(int minSdkVersion) {
AndroidManifest apkManifest =
getAndroidManifest().toEditor().setMinSdkVersion(minSdkVersion).save();
return toBuilder().setAndroidManifest(apkManifest).build();
}

/** Writes the SDK Patch version to a new <meta-data> element. */
public ModuleSplit writePatchVersion(int patchVersion) {
AndroidManifest apkManifest =
Expand Down
Loading

0 comments on commit 0b00e4a

Please sign in to comment.