Skip to content

Commit

Permalink
Prepare for release 1.15.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
sopo-c committed Oct 11, 2023
1 parent 0b9149c commit 6b51fd7
Show file tree
Hide file tree
Showing 55 changed files with 2,320 additions and 386 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.4](https://github.com/google/bundletool/releases)
Latest release: [1.15.5](https://github.com/google/bundletool/releases)
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies {
shadow "com.google.auto.value:auto-value-annotations:1.6.2"
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
shadow "com.google.errorprone:error_prone_annotations:2.3.1"
shadow "com.google.guava:guava:31.0.1-jre"
shadow "com.google.guava:guava:31.1-jre"
shadow "com.google.protobuf:protobuf-java:3.19.2"
shadow "com.google.protobuf:protobuf-java-util:3.19.2"
shadow "com.google.dagger:dagger:2.28.3"
Expand All @@ -64,7 +64,7 @@ dependencies {
testImplementation "com.google.auto.value:auto-value-annotations:1.6.2"
testAnnotationProcessor "com.google.auto.value:auto-value:1.6.2"
testImplementation "com.google.errorprone:error_prone_annotations:2.3.1"
testImplementation "com.google.guava:guava:31.0.1-jre"
testImplementation "com.google.guava:guava:31.1-jre"
testImplementation "com.google.truth.extensions:truth-java8-extension:0.45"
testImplementation "com.google.truth.extensions:truth-proto-extension:0.45"
testImplementation "com.google.jimfs:jimfs:1.1"
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.4
release_version = 1.15.5
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.android.tools.build.bundletool.model.ModuleDeliveryType;
import com.android.tools.build.bundletool.model.ModuleSplit;
import com.android.tools.build.bundletool.model.OptimizationDimension;
import com.android.tools.build.bundletool.model.ResourceId;
import com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException;
import com.android.tools.build.bundletool.model.exceptions.InvalidCommandException;
import com.android.tools.build.bundletool.model.targeting.AlternativeVariantTargetingPopulator;
Expand Down Expand Up @@ -326,10 +327,8 @@ private ApkGenerationConfiguration.Builder getCommonSplitApkGenerationConfigurat

apkGenerationConfiguration.setEnableUncompressedNativeLibraries(
apkOptimizations.getUncompressNativeLibraries());
apkGenerationConfiguration.setEnableDexCompressionSplitter(
getEnableUncompressedDexOptimization(appBundle));
apkGenerationConfiguration.setDexCompressionSplitterForTargetSdk(
apkOptimizations.getUncompressedDexTargetSdk());
setEnableUncompressedDexOptimization(appBundle, apkGenerationConfiguration);

apkGenerationConfiguration.setEnableSparseEncodingVariant(
bundleConfig
.getOptimizations()
Expand All @@ -347,10 +346,13 @@ private ApkGenerationConfiguration.Builder getCommonSplitApkGenerationConfigurat
installLocation.equals("auto") || installLocation.equals("preferExternal"))
.orElse(false));

apkGenerationConfiguration.setMasterPinnedResourceIds(appBundle.getMasterPinnedResourceIds());
apkGenerationConfiguration.setMasterPinnedResourceIds(
bundleConfig.getMasterResources().getResourceIdsList().stream()
.map(ResourceId::create)
.collect(toImmutableSet()));

apkGenerationConfiguration.setMasterPinnedResourceNames(
appBundle.getMasterPinnedResourceNames());
ImmutableSet.copyOf(bundleConfig.getMasterResources().getResourceNamesList()));

apkGenerationConfiguration.setSuffixStrippings(apkOptimizations.getSuffixStrippings());

Expand All @@ -361,21 +363,18 @@ private ApkGenerationConfiguration.Builder getCommonSplitApkGenerationConfigurat
.getMinSdkForAdditionalVariantWithV3Rotation()
.ifPresent(apkGenerationConfiguration::setMinSdkForAdditionalVariantWithV3Rotation);


return apkGenerationConfiguration;
}

private boolean getEnableUncompressedDexOptimization(AppBundle appBundle) {
private void setEnableUncompressedDexOptimization(
AppBundle appBundle, ApkGenerationConfiguration.Builder builder) {
if (appBundle.getUncompressedDexOptOut()) {
return false;
builder.setEnableDexCompressionSplitter(false);
return;
}
if (appBundle.getBundleConfig().getOptimizations().hasUncompressDexFiles()) {
// If uncompressed dex is specified in the BundleConfig it will be honoured.
return appBundle.getBundleConfig().getOptimizations().getUncompressDexFiles().getEnabled();
}
// This is the default value of the optimisation. Depends on the bundletool version.
boolean enableUncompressedDexOptimization = apkOptimizations.getUncompressDexFiles();

return enableUncompressedDexOptimization;
builder.setEnableDexCompressionSplitter(apkOptimizations.getUncompressDexFiles());
builder.setDexCompressionSplitterForTargetSdk(apkOptimizations.getUncompressedDexTargetSdk());
}

private ApkGenerationConfiguration getAssetSliceGenerationConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static com.android.tools.build.bundletool.model.utils.BundleParser.getModulesZip;
import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;

import com.android.tools.build.bundletool.androidtools.Aapt2Command;
import com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription;
Expand All @@ -32,6 +33,7 @@
import com.android.tools.build.bundletool.model.ApkListener;
import com.android.tools.build.bundletool.model.ApkModifier;
import com.android.tools.build.bundletool.model.Password;
import com.android.tools.build.bundletool.model.SdkAsar;
import com.android.tools.build.bundletool.model.SdkBundle;
import com.android.tools.build.bundletool.model.SignerConfig;
import com.android.tools.build.bundletool.model.SigningConfiguration;
Expand All @@ -40,6 +42,7 @@
import com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider;
import com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider;
import com.android.tools.build.bundletool.model.utils.files.FilePreconditions;
import com.android.tools.build.bundletool.validation.SdkAsarValidator;
import com.android.tools.build.bundletool.validation.SdkBundleValidator;
import com.google.auto.value.AutoValue;
import com.google.common.util.concurrent.ListeningExecutorService;
Expand Down Expand Up @@ -72,6 +75,7 @@ public enum OutputFormat {
}

private static final Flag<Path> SDK_BUNDLE_LOCATION_FLAG = Flag.path("sdk-bundle");
private static final Flag<Path> SDK_ARCHIVE_LOCATION_FLAG = Flag.path("sdk-archive");
private static final Flag<Integer> VERSION_CODE_FLAG = Flag.positiveInteger("version-code");
private static final Flag<Path> OUTPUT_FILE_FLAG = Flag.path("output");
private static final Flag<OutputFormat> OUTPUT_FORMAT_FLAG =
Expand All @@ -90,7 +94,9 @@ public enum OutputFormat {
private static final SystemEnvironmentProvider DEFAULT_PROVIDER =
new DefaultSystemEnvironmentProvider();

abstract Path getSdkBundlePath();
abstract Optional<Path> getSdkBundlePath();

abstract Optional<Path> getSdkArchivePath();

abstract Integer getVersionCode();

Expand Down Expand Up @@ -120,6 +126,7 @@ ListeningExecutorService getExecutorService() {

public abstract Optional<Integer> getFirstVariantNumber();


/** Creates a builder for the {@link BuildSdkApksCommand} with some default settings. */
public static BuildSdkApksCommand.Builder builder() {
return new AutoValue_BuildSdkApksCommand.Builder()
Expand All @@ -135,6 +142,9 @@ public abstract static class Builder {
/** Sets the path to the input SDK bundle. Must have the extension ".asb". */
public abstract Builder setSdkBundlePath(Path sdkBundlePath);

/** Sets the path to the input SDK archive. Must have the extension ".asar". */
public abstract Builder setSdkArchivePath(Path sdkArchivePath);

/** Sets the SDK version code */
public abstract Builder setVersionCode(Integer versionCode);

Expand Down Expand Up @@ -220,6 +230,7 @@ public Builder setExecutorService(ListeningExecutorService executorService) {
*/
public abstract Builder setFirstVariantNumber(int firstVariantNumber);


abstract BuildSdkApksCommand autoBuild();

/**
Expand All @@ -232,7 +243,11 @@ public BuildSdkApksCommand build() {
setExecutorServiceInternal(createInternalExecutorService(DEFAULT_THREAD_POOL_SIZE));
setExecutorServiceCreatedByBundleTool(true);
}
return autoBuild();
BuildSdkApksCommand command = autoBuild();
checkState(
command.getSdkBundlePath().isPresent() ^ command.getSdkArchivePath().isPresent(),
"One and only one of SdkBundlePath and SdkArchivePath should be set.");
return command;
}
}

Expand All @@ -244,10 +259,11 @@ static BuildSdkApksCommand fromFlags(
ParsedFlags flags, PrintStream out, SystemEnvironmentProvider provider) {
Builder sdkApksCommandBuilder =
BuildSdkApksCommand.builder()
.setSdkBundlePath(SDK_BUNDLE_LOCATION_FLAG.getRequiredValue(flags))
.setOutputFile(OUTPUT_FILE_FLAG.getRequiredValue(flags));

// Optional arguments.
SDK_BUNDLE_LOCATION_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setSdkBundlePath);
SDK_ARCHIVE_LOCATION_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setSdkArchivePath);
OUTPUT_FORMAT_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setOutputFormat);
OVERWRITE_OUTPUT_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setOverwriteOutput);
VERSION_CODE_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setVersionCode);
Expand Down Expand Up @@ -275,8 +291,19 @@ static BuildSdkApksCommand fromFlags(

public Path execute() {
validateInput();
if (getSdkBundlePath().isPresent()) {
executeForSdkBundle();
} else if (getSdkArchivePath().isPresent()) {
executeForSdkArchive();
} else {
throw new IllegalStateException(
"One and only one of SdkBundlePath and SdkArchivePath should be set.");
}
return getOutputFile();
}

try (ZipFile bundleZip = new ZipFile(getSdkBundlePath().toFile());
private void executeForSdkBundle() {
try (ZipFile bundleZip = new ZipFile(getSdkBundlePath().get().toFile());
TempDirectory tempDir = new TempDirectory(getClass().getSimpleName())) {

SdkBundleValidator bundleValidator = SdkBundleValidator.create();
Expand All @@ -287,34 +314,64 @@ public Path execute() {
bundleValidator.validateModulesFile(modulesZip);
SdkBundle sdkBundle = SdkBundle.buildFromZip(bundleZip, modulesZip, getVersionCode());
bundleValidator.validate(sdkBundle);

DaggerBuildSdkApksManagerComponent.builder()
.setBuildSdkApksCommand(this)
.setTempDirectory(tempDir)
.setSdkBundle(sdkBundle)
.build()
.create()
.execute();
executeBuildSdkApksManager(sdkBundle, tempDir);
}
} catch (ZipException e) {
throw InvalidBundleException.builder()
.withCause(e)
.withUserMessage("The SDK Bundle is not a valid zip file.")
.build();
} catch (IOException e) {
throw new UncheckedIOException("An error occurred when validating the Sdk Bundle.", e);
throw new UncheckedIOException("An error occurred when processing the Sdk Bundle.", e);
} finally {
if (isExecutorServiceCreatedByBundleTool()) {
getExecutorService().shutdown();
}
}
}

return getOutputFile();
private void executeForSdkArchive() {
try (ZipFile sdkAsarZip = new ZipFile(getSdkArchivePath().get().toFile());
TempDirectory tempDir = new TempDirectory(getClass().getSimpleName())) {

SdkAsarValidator.validateFile(sdkAsarZip);

Path modulesPath = tempDir.getPath().resolve(EXTRACTED_SDK_MODULES_FILE_NAME);
try (ZipFile modulesZip = getModulesZip(sdkAsarZip, modulesPath)) {
SdkAsarValidator.validateModulesFile(modulesZip);
SdkAsar sdkAsar = SdkAsar.buildFromZip(sdkAsarZip, modulesZip, modulesPath);
SdkBundle sdkBundle = SdkBundle.buildFromAsar(sdkAsar, getVersionCode());
SdkBundleValidator.create().validate(sdkBundle);
executeBuildSdkApksManager(sdkBundle, tempDir);
}
} catch (ZipException e) {
throw InvalidBundleException.builder()
.withCause(e)
.withUserMessage("The SDK archive is not a valid zip file.")
.build();
} catch (IOException e) {
throw new UncheckedIOException("An error occurred when processing the Sdk archive.", e);
} finally {
if (isExecutorServiceCreatedByBundleTool()) {
getExecutorService().shutdown();
}
}
}

private void executeBuildSdkApksManager(SdkBundle sdkBundle, TempDirectory tempDir)
throws IOException {
DaggerBuildSdkApksManagerComponent.builder()
.setBuildSdkApksCommand(this)
.setTempDirectory(tempDir)
.setSdkBundle(sdkBundle)
.build()
.create()
.execute();
}

private void validateInput() {
FilePreconditions.checkFileExistsAndReadable(getSdkBundlePath());
FilePreconditions.checkFileHasExtension("ASB file", getSdkBundlePath(), ".asb");
getSdkBundlePath().ifPresent(BuildSdkApksCommand::validateSdkBundlePath);
getSdkArchivePath().ifPresent(BuildSdkApksCommand::validateSdkArchivePath);

switch (getOutputFormat()) {
case APK_SET:
Expand Down Expand Up @@ -344,6 +401,16 @@ private static ListeningExecutorService createInternalExecutorService(int maxThr
return MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(maxThreads));
}

private static void validateSdkBundlePath(Path sdkBundlePath) {
FilePreconditions.checkFileExistsAndReadable(sdkBundlePath);
FilePreconditions.checkFileHasExtension("ASB file", sdkBundlePath, ".asb");
}

private static void validateSdkArchivePath(Path sdkArchivePath) {
FilePreconditions.checkFileExistsAndReadable(sdkArchivePath);
FilePreconditions.checkFileHasExtension("ASAR file", sdkArchivePath, ".asar");
}

public static CommandHelp help() {
return CommandHelp.builder()
.setCommandName(COMMAND_NAME)
Expand All @@ -355,7 +422,17 @@ public static CommandHelp help() {
FlagDescription.builder()
.setFlagName(SDK_BUNDLE_LOCATION_FLAG.getName())
.setExampleValue("path/to/SDKbundle.asb")
.setDescription("Path to SDK bundle. Must have the extension '.asb'.")
.setDescription(
"Path to SDK bundle. Must have the extension '.asb'. Cannot be used together"
+ " with the `sdk-archive` flag.")
.build())
.addFlag(
FlagDescription.builder()
.setFlagName(SDK_ARCHIVE_LOCATION_FLAG.getName())
.setExampleValue("path/to/sdk.asar")
.setDescription(
"Path to SDK archive. Must have the extension '.asar'. Cannot be used together"
+ " with the `sdk-bundle` flag.")
.build())
.addFlag(
FlagDescription.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public abstract class InstallMultiApksCommand {

public static final ImmutableMap<String, String> NONUPDATABLE_PACKAGES_PAIRS =
ImmutableMap.of(
"com.google.android.ext.service", "com.google.android.extservice",
"com.google.android.ext.services", "com.google.android.extservices",
"com.google.android.permissioncontroller", "com.google.android.permission");

private static final Flag<Path> ADB_PATH_FLAG = Flag.path("adb");
Expand Down
Loading

0 comments on commit 6b51fd7

Please sign in to comment.