Skip to content

Commit 6b51fd7

Browse files
committed
Prepare for release 1.15.5.
1 parent 0b9149c commit 6b51fd7

File tree

55 files changed

+2320
-386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2320
-386
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ https://developer.android.com/studio/command-line/bundletool
4646

4747
## Releases
4848

49-
Latest release: [1.15.4](https://github.com/google/bundletool/releases)
49+
Latest release: [1.15.5](https://github.com/google/bundletool/releases)

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies {
4141
shadow "com.google.auto.value:auto-value-annotations:1.6.2"
4242
annotationProcessor "com.google.auto.value:auto-value:1.6.2"
4343
shadow "com.google.errorprone:error_prone_annotations:2.3.1"
44-
shadow "com.google.guava:guava:31.0.1-jre"
44+
shadow "com.google.guava:guava:31.1-jre"
4545
shadow "com.google.protobuf:protobuf-java:3.19.2"
4646
shadow "com.google.protobuf:protobuf-java-util:3.19.2"
4747
shadow "com.google.dagger:dagger:2.28.3"
@@ -64,7 +64,7 @@ dependencies {
6464
testImplementation "com.google.auto.value:auto-value-annotations:1.6.2"
6565
testAnnotationProcessor "com.google.auto.value:auto-value:1.6.2"
6666
testImplementation "com.google.errorprone:error_prone_annotations:2.3.1"
67-
testImplementation "com.google.guava:guava:31.0.1-jre"
67+
testImplementation "com.google.guava:guava:31.1-jre"
6868
testImplementation "com.google.truth.extensions:truth-java8-extension:0.45"
6969
testImplementation "com.google.truth.extensions:truth-proto-extension:0.45"
7070
testImplementation "com.google.jimfs:jimfs:1.1"

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
release_version = 1.15.4
1+
release_version = 1.15.5

src/main/java/com/android/tools/build/bundletool/commands/BuildApksManager.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.android.tools.build.bundletool.model.ModuleDeliveryType;
4646
import com.android.tools.build.bundletool.model.ModuleSplit;
4747
import com.android.tools.build.bundletool.model.OptimizationDimension;
48+
import com.android.tools.build.bundletool.model.ResourceId;
4849
import com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException;
4950
import com.android.tools.build.bundletool.model.exceptions.InvalidCommandException;
5051
import com.android.tools.build.bundletool.model.targeting.AlternativeVariantTargetingPopulator;
@@ -326,10 +327,8 @@ private ApkGenerationConfiguration.Builder getCommonSplitApkGenerationConfigurat
326327

327328
apkGenerationConfiguration.setEnableUncompressedNativeLibraries(
328329
apkOptimizations.getUncompressNativeLibraries());
329-
apkGenerationConfiguration.setEnableDexCompressionSplitter(
330-
getEnableUncompressedDexOptimization(appBundle));
331-
apkGenerationConfiguration.setDexCompressionSplitterForTargetSdk(
332-
apkOptimizations.getUncompressedDexTargetSdk());
330+
setEnableUncompressedDexOptimization(appBundle, apkGenerationConfiguration);
331+
333332
apkGenerationConfiguration.setEnableSparseEncodingVariant(
334333
bundleConfig
335334
.getOptimizations()
@@ -347,10 +346,13 @@ private ApkGenerationConfiguration.Builder getCommonSplitApkGenerationConfigurat
347346
installLocation.equals("auto") || installLocation.equals("preferExternal"))
348347
.orElse(false));
349348

350-
apkGenerationConfiguration.setMasterPinnedResourceIds(appBundle.getMasterPinnedResourceIds());
349+
apkGenerationConfiguration.setMasterPinnedResourceIds(
350+
bundleConfig.getMasterResources().getResourceIdsList().stream()
351+
.map(ResourceId::create)
352+
.collect(toImmutableSet()));
351353

352354
apkGenerationConfiguration.setMasterPinnedResourceNames(
353-
appBundle.getMasterPinnedResourceNames());
355+
ImmutableSet.copyOf(bundleConfig.getMasterResources().getResourceNamesList()));
354356

355357
apkGenerationConfiguration.setSuffixStrippings(apkOptimizations.getSuffixStrippings());
356358

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

366+
364367
return apkGenerationConfiguration;
365368
}
366369

367-
private boolean getEnableUncompressedDexOptimization(AppBundle appBundle) {
370+
private void setEnableUncompressedDexOptimization(
371+
AppBundle appBundle, ApkGenerationConfiguration.Builder builder) {
368372
if (appBundle.getUncompressedDexOptOut()) {
369-
return false;
373+
builder.setEnableDexCompressionSplitter(false);
374+
return;
370375
}
371-
if (appBundle.getBundleConfig().getOptimizations().hasUncompressDexFiles()) {
372-
// If uncompressed dex is specified in the BundleConfig it will be honoured.
373-
return appBundle.getBundleConfig().getOptimizations().getUncompressDexFiles().getEnabled();
374-
}
375-
// This is the default value of the optimisation. Depends on the bundletool version.
376-
boolean enableUncompressedDexOptimization = apkOptimizations.getUncompressDexFiles();
377-
378-
return enableUncompressedDexOptimization;
376+
builder.setEnableDexCompressionSplitter(apkOptimizations.getUncompressDexFiles());
377+
builder.setDexCompressionSplitterForTargetSdk(apkOptimizations.getUncompressedDexTargetSdk());
379378
}
380379

381380
private ApkGenerationConfiguration getAssetSliceGenerationConfiguration() {

src/main/java/com/android/tools/build/bundletool/commands/BuildSdkApksCommand.java

Lines changed: 94 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static com.android.tools.build.bundletool.model.utils.BundleParser.getModulesZip;
2323
import static com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist;
2424
import static com.google.common.base.Preconditions.checkArgument;
25+
import static com.google.common.base.Preconditions.checkState;
2526

2627
import com.android.tools.build.bundletool.androidtools.Aapt2Command;
2728
import com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription;
@@ -32,6 +33,7 @@
3233
import com.android.tools.build.bundletool.model.ApkListener;
3334
import com.android.tools.build.bundletool.model.ApkModifier;
3435
import com.android.tools.build.bundletool.model.Password;
36+
import com.android.tools.build.bundletool.model.SdkAsar;
3537
import com.android.tools.build.bundletool.model.SdkBundle;
3638
import com.android.tools.build.bundletool.model.SignerConfig;
3739
import com.android.tools.build.bundletool.model.SigningConfiguration;
@@ -40,6 +42,7 @@
4042
import com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider;
4143
import com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider;
4244
import com.android.tools.build.bundletool.model.utils.files.FilePreconditions;
45+
import com.android.tools.build.bundletool.validation.SdkAsarValidator;
4346
import com.android.tools.build.bundletool.validation.SdkBundleValidator;
4447
import com.google.auto.value.AutoValue;
4548
import com.google.common.util.concurrent.ListeningExecutorService;
@@ -72,6 +75,7 @@ public enum OutputFormat {
7275
}
7376

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

93-
abstract Path getSdkBundlePath();
97+
abstract Optional<Path> getSdkBundlePath();
98+
99+
abstract Optional<Path> getSdkArchivePath();
94100

95101
abstract Integer getVersionCode();
96102

@@ -120,6 +126,7 @@ ListeningExecutorService getExecutorService() {
120126

121127
public abstract Optional<Integer> getFirstVariantNumber();
122128

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

145+
/** Sets the path to the input SDK archive. Must have the extension ".asar". */
146+
public abstract Builder setSdkArchivePath(Path sdkArchivePath);
147+
138148
/** Sets the SDK version code */
139149
public abstract Builder setVersionCode(Integer versionCode);
140150

@@ -220,6 +230,7 @@ public Builder setExecutorService(ListeningExecutorService executorService) {
220230
*/
221231
public abstract Builder setFirstVariantNumber(int firstVariantNumber);
222232

233+
223234
abstract BuildSdkApksCommand autoBuild();
224235

225236
/**
@@ -232,7 +243,11 @@ public BuildSdkApksCommand build() {
232243
setExecutorServiceInternal(createInternalExecutorService(DEFAULT_THREAD_POOL_SIZE));
233244
setExecutorServiceCreatedByBundleTool(true);
234245
}
235-
return autoBuild();
246+
BuildSdkApksCommand command = autoBuild();
247+
checkState(
248+
command.getSdkBundlePath().isPresent() ^ command.getSdkArchivePath().isPresent(),
249+
"One and only one of SdkBundlePath and SdkArchivePath should be set.");
250+
return command;
236251
}
237252
}
238253

@@ -244,10 +259,11 @@ static BuildSdkApksCommand fromFlags(
244259
ParsedFlags flags, PrintStream out, SystemEnvironmentProvider provider) {
245260
Builder sdkApksCommandBuilder =
246261
BuildSdkApksCommand.builder()
247-
.setSdkBundlePath(SDK_BUNDLE_LOCATION_FLAG.getRequiredValue(flags))
248262
.setOutputFile(OUTPUT_FILE_FLAG.getRequiredValue(flags));
249263

250264
// Optional arguments.
265+
SDK_BUNDLE_LOCATION_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setSdkBundlePath);
266+
SDK_ARCHIVE_LOCATION_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setSdkArchivePath);
251267
OUTPUT_FORMAT_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setOutputFormat);
252268
OVERWRITE_OUTPUT_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setOverwriteOutput);
253269
VERSION_CODE_FLAG.getValue(flags).ifPresent(sdkApksCommandBuilder::setVersionCode);
@@ -275,8 +291,19 @@ static BuildSdkApksCommand fromFlags(
275291

276292
public Path execute() {
277293
validateInput();
294+
if (getSdkBundlePath().isPresent()) {
295+
executeForSdkBundle();
296+
} else if (getSdkArchivePath().isPresent()) {
297+
executeForSdkArchive();
298+
} else {
299+
throw new IllegalStateException(
300+
"One and only one of SdkBundlePath and SdkArchivePath should be set.");
301+
}
302+
return getOutputFile();
303+
}
278304

279-
try (ZipFile bundleZip = new ZipFile(getSdkBundlePath().toFile());
305+
private void executeForSdkBundle() {
306+
try (ZipFile bundleZip = new ZipFile(getSdkBundlePath().get().toFile());
280307
TempDirectory tempDir = new TempDirectory(getClass().getSimpleName())) {
281308

282309
SdkBundleValidator bundleValidator = SdkBundleValidator.create();
@@ -287,34 +314,64 @@ public Path execute() {
287314
bundleValidator.validateModulesFile(modulesZip);
288315
SdkBundle sdkBundle = SdkBundle.buildFromZip(bundleZip, modulesZip, getVersionCode());
289316
bundleValidator.validate(sdkBundle);
290-
291-
DaggerBuildSdkApksManagerComponent.builder()
292-
.setBuildSdkApksCommand(this)
293-
.setTempDirectory(tempDir)
294-
.setSdkBundle(sdkBundle)
295-
.build()
296-
.create()
297-
.execute();
317+
executeBuildSdkApksManager(sdkBundle, tempDir);
298318
}
299319
} catch (ZipException e) {
300320
throw InvalidBundleException.builder()
301321
.withCause(e)
302322
.withUserMessage("The SDK Bundle is not a valid zip file.")
303323
.build();
304324
} catch (IOException e) {
305-
throw new UncheckedIOException("An error occurred when validating the Sdk Bundle.", e);
325+
throw new UncheckedIOException("An error occurred when processing the Sdk Bundle.", e);
306326
} finally {
307327
if (isExecutorServiceCreatedByBundleTool()) {
308328
getExecutorService().shutdown();
309329
}
310330
}
331+
}
311332

312-
return getOutputFile();
333+
private void executeForSdkArchive() {
334+
try (ZipFile sdkAsarZip = new ZipFile(getSdkArchivePath().get().toFile());
335+
TempDirectory tempDir = new TempDirectory(getClass().getSimpleName())) {
336+
337+
SdkAsarValidator.validateFile(sdkAsarZip);
338+
339+
Path modulesPath = tempDir.getPath().resolve(EXTRACTED_SDK_MODULES_FILE_NAME);
340+
try (ZipFile modulesZip = getModulesZip(sdkAsarZip, modulesPath)) {
341+
SdkAsarValidator.validateModulesFile(modulesZip);
342+
SdkAsar sdkAsar = SdkAsar.buildFromZip(sdkAsarZip, modulesZip, modulesPath);
343+
SdkBundle sdkBundle = SdkBundle.buildFromAsar(sdkAsar, getVersionCode());
344+
SdkBundleValidator.create().validate(sdkBundle);
345+
executeBuildSdkApksManager(sdkBundle, tempDir);
346+
}
347+
} catch (ZipException e) {
348+
throw InvalidBundleException.builder()
349+
.withCause(e)
350+
.withUserMessage("The SDK archive is not a valid zip file.")
351+
.build();
352+
} catch (IOException e) {
353+
throw new UncheckedIOException("An error occurred when processing the Sdk archive.", e);
354+
} finally {
355+
if (isExecutorServiceCreatedByBundleTool()) {
356+
getExecutorService().shutdown();
357+
}
358+
}
359+
}
360+
361+
private void executeBuildSdkApksManager(SdkBundle sdkBundle, TempDirectory tempDir)
362+
throws IOException {
363+
DaggerBuildSdkApksManagerComponent.builder()
364+
.setBuildSdkApksCommand(this)
365+
.setTempDirectory(tempDir)
366+
.setSdkBundle(sdkBundle)
367+
.build()
368+
.create()
369+
.execute();
313370
}
314371

315372
private void validateInput() {
316-
FilePreconditions.checkFileExistsAndReadable(getSdkBundlePath());
317-
FilePreconditions.checkFileHasExtension("ASB file", getSdkBundlePath(), ".asb");
373+
getSdkBundlePath().ifPresent(BuildSdkApksCommand::validateSdkBundlePath);
374+
getSdkArchivePath().ifPresent(BuildSdkApksCommand::validateSdkArchivePath);
318375

319376
switch (getOutputFormat()) {
320377
case APK_SET:
@@ -344,6 +401,16 @@ private static ListeningExecutorService createInternalExecutorService(int maxThr
344401
return MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(maxThreads));
345402
}
346403

404+
private static void validateSdkBundlePath(Path sdkBundlePath) {
405+
FilePreconditions.checkFileExistsAndReadable(sdkBundlePath);
406+
FilePreconditions.checkFileHasExtension("ASB file", sdkBundlePath, ".asb");
407+
}
408+
409+
private static void validateSdkArchivePath(Path sdkArchivePath) {
410+
FilePreconditions.checkFileExistsAndReadable(sdkArchivePath);
411+
FilePreconditions.checkFileHasExtension("ASAR file", sdkArchivePath, ".asar");
412+
}
413+
347414
public static CommandHelp help() {
348415
return CommandHelp.builder()
349416
.setCommandName(COMMAND_NAME)
@@ -355,7 +422,17 @@ public static CommandHelp help() {
355422
FlagDescription.builder()
356423
.setFlagName(SDK_BUNDLE_LOCATION_FLAG.getName())
357424
.setExampleValue("path/to/SDKbundle.asb")
358-
.setDescription("Path to SDK bundle. Must have the extension '.asb'.")
425+
.setDescription(
426+
"Path to SDK bundle. Must have the extension '.asb'. Cannot be used together"
427+
+ " with the `sdk-archive` flag.")
428+
.build())
429+
.addFlag(
430+
FlagDescription.builder()
431+
.setFlagName(SDK_ARCHIVE_LOCATION_FLAG.getName())
432+
.setExampleValue("path/to/sdk.asar")
433+
.setDescription(
434+
"Path to SDK archive. Must have the extension '.asar'. Cannot be used together"
435+
+ " with the `sdk-bundle` flag.")
359436
.build())
360437
.addFlag(
361438
FlagDescription.builder()

src/main/java/com/android/tools/build/bundletool/commands/InstallMultiApksCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public abstract class InstallMultiApksCommand {
9191

9292
public static final ImmutableMap<String, String> NONUPDATABLE_PACKAGES_PAIRS =
9393
ImmutableMap.of(
94-
"com.google.android.ext.service", "com.google.android.extservice",
94+
"com.google.android.ext.services", "com.google.android.extservices",
9595
"com.google.android.permissioncontroller", "com.google.android.permission");
9696

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

0 commit comments

Comments
 (0)