Skip to content

Commit

Permalink
Prepare for release 1.13.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Iurii Makhno committed Nov 3, 2022
1 parent d01b978 commit 8ab1a9f
Show file tree
Hide file tree
Showing 30 changed files with 806 additions and 226 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.12.1](https://github.com/google/bundletool/releases)
Latest release: [1.13.0](https://github.com/google/bundletool/releases)
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ dependencies {
}
shadow "org.slf4j:slf4j-api:1.7.30"

implementationWindows "com.android.tools.build:aapt2:7.3.0-alpha07-8248216:windows"
implementationMacOs "com.android.tools.build:aapt2:7.3.0-alpha07-8248216:osx"
implementationLinux "com.android.tools.build:aapt2:7.3.0-alpha07-8248216:linux"
implementationWindows "com.android.tools.build:aapt2:8.0.0-alpha07-9193536:windows"
implementationMacOs "com.android.tools.build:aapt2:8.0.0-alpha07-9193536:osx"
implementationLinux "com.android.tools.build:aapt2:8.0.0-alpha07-9193536:linux"

compileOnly "org.bouncycastle:bcprov-jdk15on:1.56"
compileOnly "org.bouncycastle:bcpkix-jdk15on:1.56"
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.12.1
release_version = 1.13.0
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ static void main(String[] args, Runtime runtime) {
case BuildSdkAsarCommand.COMMAND_NAME:
BuildSdkAsarCommand.fromFlags(flags).execute();
break;
case PrintDeviceTargetingConfigCommand.COMMAND_NAME:
PrintDeviceTargetingConfigCommand.fromFlags(flags).execute();
break;
case EvaluateDeviceTargetingConfigCommand.COMMAND_NAME:
try (AdbServer adbServer = DdmlibAdbServer.getInstance()) {
EvaluateDeviceTargetingConfigCommand.fromFlags(flags, adbServer).execute(System.out);
}
break;
case ExtractApksCommand.COMMAND_NAME:
ExtractApksCommand.fromFlags(flags).execute();
break;
Expand Down Expand Up @@ -161,6 +169,11 @@ public static void help() {
ImmutableList.of(
BuildBundleCommand.help(),
BuildApksCommand.help(),
BuildSdkBundleCommand.help(),
BuildSdkApksCommand.help(),
BuildSdkAsarCommand.help(),
PrintDeviceTargetingConfigCommand.help(),
EvaluateDeviceTargetingConfigCommand.help(),
ExtractApksCommand.help(),
GetDeviceSpecCommand.help(),
InstallApksCommand.help(),
Expand Down Expand Up @@ -196,6 +209,12 @@ public static void help(String commandName, Runtime runtime) {
case BuildSdkAsarCommand.COMMAND_NAME:
commandHelp = BuildSdkAsarCommand.help();
break;
case PrintDeviceTargetingConfigCommand.COMMAND_NAME:
commandHelp = PrintDeviceTargetingConfigCommand.help();
break;
case EvaluateDeviceTargetingConfigCommand.COMMAND_NAME:
commandHelp = EvaluateDeviceTargetingConfigCommand.help();
break;
case ExtractApksCommand.COMMAND_NAME:
commandHelp = ExtractApksCommand.help();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.common.collect.ImmutableList;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Optional;

/** Exposes aapt2 commands used by Bundle Tool. */
public interface Aapt2Command {
Expand All @@ -43,6 +44,22 @@ public void convertApkProtoToBinary(
Path protoApk, Path binaryApk, ConvertOptions convertOptions) {
ImmutableList.Builder<String> convertCommand =
ImmutableList.<String>builder().add(aapt2Path.toString()).add("convert");
if (convertOptions.getForceSparseEncoding()) {
convertCommand.add("--force-sparse-encoding");
}
if (convertOptions.getCollapseResourceNames()) {
convertCommand.add("--collapse-resource-names");
}
if (convertOptions.getDeduplicateResourceEntries()) {
convertCommand.add("--deduplicate-entry-values");
}
convertOptions
.getResourceConfigPath()
.ifPresent(
path ->
convertCommand
.add("--resources-config-path")
.add(path.toAbsolutePath().toString()));
convertCommand
.add("--output-format")
.add("binary")
Expand Down Expand Up @@ -85,15 +102,30 @@ public ImmutableList<String> dumpBadging(Path apkPath) {
abstract class ConvertOptions {
public abstract boolean getForceSparseEncoding();

public abstract boolean getCollapseResourceNames();

public abstract Optional<Path> getResourceConfigPath();

public abstract boolean getDeduplicateResourceEntries();

public static Builder builder() {
return new AutoValue_Aapt2Command_ConvertOptions.Builder().setForceSparseEncoding(false);
return new AutoValue_Aapt2Command_ConvertOptions.Builder()
.setForceSparseEncoding(false)
.setCollapseResourceNames(false)
.setDeduplicateResourceEntries(false);
}

/** Builder for {@link ConvertOptions}. */
@AutoValue.Builder
public abstract static class Builder {
public abstract Builder setForceSparseEncoding(boolean value);

public abstract Builder setCollapseResourceNames(boolean value);

public abstract Builder setResourceConfigPath(Optional<Path> resourceConfigPath);

public abstract Builder setDeduplicateResourceEntries(boolean value);

public abstract ConvertOptions build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ public ModuleSplit generateArchivedApk(
extraResourceNameToIdMap.get(ArchivedResourcesHelper.OPACITY_LAYER_DRAWABLE_NAME),
iconAttribute,
roundIconAttribute,
archivedResourcesHelper.getArchivedClassesDexPath(appBundle));
archivedResourcesHelper.findArchivedClassesDexPath(
appBundle.getVersion(),
BundleTransparencyCheckUtils.isTransparencyEnabled(appBundle)));

archivedManifest =
ArchivedAndroidManifestUtils.updateArchivedIcons(
Expand All @@ -99,7 +101,9 @@ public ModuleSplit generateArchivedApk(
ImmutableMap.of(
BundleModule.DEX_DIRECTORY.resolve("classes.dex"),
resourceReader.getResourceByteSource(
archivedResourcesHelper.getArchivedClassesDexPath(appBundle)));
archivedResourcesHelper.findArchivedClassesDexPath(
appBundle.getVersion(),
BundleTransparencyCheckUtils.isTransparencyEnabled(appBundle))));
}

ModuleSplit moduleSplit =
Expand All @@ -120,7 +124,7 @@ public ModuleSplit generateArchivedApk(
private void validateRequest(AppBundle appBundle) {
checkNotNull(appBundle);

if (!ArchivedBundleUtils.isStoreArchiveEnabled(appBundle)) {
if (!appBundle.getStoreArchive().orElse(true)) {
throw InvalidCommandException.builder()
.withInternalMessage(
"Archived APK cannot be generated when Store Archive configuration is disabled.")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static java.util.Comparator.reverseOrder;

import com.android.tools.build.bundletool.io.ResourceReader;
import com.android.tools.build.bundletool.model.AppBundle;
import com.android.tools.build.bundletool.model.BundleModule;
import com.android.tools.build.bundletool.model.ResourceInjector;
import com.android.tools.build.bundletool.model.ZipPath;
Expand All @@ -32,9 +31,7 @@
import com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttributeBuilder;
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.android.tools.build.bundletool.model.version.Version;
import com.android.tools.build.bundletool.transparency.BundleTransparencyCheckUtils;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.ByteSource;
Expand Down Expand Up @@ -63,8 +60,6 @@ public final class ArchivedResourcesHelper {
public static final String ARCHIVED_CLASSES_DEX_PATH_PREFIX =
"/com/android/tools/build/bundletool/archive/dex";
private static final String ARCHIVED_CLASSES_DEX_PATH_SUFFIX = "classes.dex";
public static final String DEFAULT_ARCHIVED_CLASSES_DEX_PATH =
getArchivedClassesDexPath(Version.of("1.8.2"));
public static final String CLOUD_SYMBOL_PATH =
"/com/android/tools/build/bundletool/archive/drawable/cloud_symbol_xml.pb";
public static final String OPACITY_LAYER_PATH =
Expand All @@ -78,19 +73,13 @@ public ArchivedResourcesHelper(ResourceReader resourceReader) {
}

/**
* Returns a path to the appropriate DEX file for {@link AppBundle}
* Returns a path to the appropriate DEX file based on the bundletool {@link Version} and if
* transparency is enabled.
*
* @throws IOException if an error occurs during reading resources from {@value
* @throws IOException if an error occurs during reading resources from {@value *
* #ARCHIVED_CLASSES_DEX_PATH_PREFIX} path
*/
public String getArchivedClassesDexPath(AppBundle bundle) throws IOException {
Version bundleToolVersion =
BundleToolVersion.getVersionFromBundleConfig(bundle.getBundleConfig());
boolean transparencyEnabled = BundleTransparencyCheckUtils.isTransparencyEnabled(bundle);
return getArchivedClassesDexPath(bundleToolVersion, transparencyEnabled);
}

private String getArchivedClassesDexPath(Version bundleToolVersion, boolean transparencyEnabled)
public String findArchivedClassesDexPath(Version bundleToolVersion, boolean transparencyEnabled)
throws IOException {
try {
ImmutableList<Path> allResources =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Streams.stream;

import com.android.bundle.Config.BundleConfig;
import com.android.bundle.Config.ResourceOptimizations.CollapsedResourceNames;
import com.android.bundle.Config.ResourceOptimizations.ResourceTypeAndName;
import com.android.tools.build.bundletool.androidtools.Aapt2Command;
import com.android.tools.build.bundletool.androidtools.Aapt2Command.ConvertOptions;
import com.android.tools.build.bundletool.model.Bundle;
import com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry;
import com.android.tools.build.bundletool.model.ModuleEntry;
import com.android.tools.build.bundletool.model.ModuleSplit;
import com.android.tools.build.bundletool.model.ZipPath;
import com.android.tools.build.bundletool.model.utils.ZipUtils;
import com.android.zipflinger.ZipArchive;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Streams;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
Expand All @@ -46,11 +53,24 @@ class Aapt2ResourceConverter {

private final Aapt2Command aapt2Command;
private final ListeningExecutorService executorService;
private final CollapsedResourceNames collapsedResourceNames;

private final Supplier<Optional<Path>> resourceConfigSupplier;

@Inject
Aapt2ResourceConverter(Aapt2Command aapt2Command, ListeningExecutorService executorService) {
Aapt2ResourceConverter(
Aapt2Command aapt2Command,
ListeningExecutorService executorService,
Bundle bundle,
BundleConfig bundleConfig,
TempDirectory tempDirectory) {
this.aapt2Command = aapt2Command;
this.executorService = executorService;
this.collapsedResourceNames =
bundleConfig.getOptimizations().getResourceOptimizations().getCollapsedResourceNames();
resourceConfigSupplier =
Suppliers.memoize(
() -> createResourceConfig(tempDirectory, bundle, collapsedResourceNames));
}

/**
Expand Down Expand Up @@ -138,7 +158,12 @@ private Path convertAndOptimizeProtoApk(ModuleSplit split, Path protoApkPath) {
aapt2Command.convertApkProtoToBinary(
protoApkPath,
binaryApkPath,
ConvertOptions.builder().setForceSparseEncoding(split.getSparseEncoding()).build());
ConvertOptions.builder()
.setForceSparseEncoding(split.getSparseEncoding())
.setCollapseResourceNames(collapsedResourceNames.getCollapseResourceNames())
.setDeduplicateResourceEntries(collapsedResourceNames.getDeduplicateResourceEntries())
.setResourceConfigPath(resourceConfigSupplier.get())
.build());
return binaryApkPath;
}

Expand Down Expand Up @@ -192,4 +217,56 @@ private ModuleSplit withConvertedEntries(ModuleSplit split, Path binaryApkPath)
return split.toBuilder().setEntries(allEntries).build();
}
}

private static Optional<Path> createResourceConfig(
TempDirectory tempDirectory, Bundle bundle, CollapsedResourceNames collapsedResourceNames) {
if (!collapsedResourceNames.getCollapseResourceNames()
|| (collapsedResourceNames.getNoCollapseResourcesCount() == 0
&& collapsedResourceNames.getNoCollapseResourceTypesCount() == 0)) {
return Optional.empty();
}
try {
Path resourceConfigPath =
Files.createTempFile(tempDirectory.getPath(), "aapt2-resource", ".cfg");

ImmutableList<String> configLines =
Stream.concat(
collapsedResourceNames.getNoCollapseResourcesList().stream(),
expandExcludedResourceTypes(bundle, collapsedResourceNames).stream())
.map(
typeAndName ->
String.format(
"%s/%s#no_collapse", typeAndName.getType(), typeAndName.getName()))
.collect(toImmutableList());
Files.write(resourceConfigPath, configLines);
return Optional.of(resourceConfigPath);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

private static ImmutableList<ResourceTypeAndName> expandExcludedResourceTypes(
Bundle bundle, CollapsedResourceNames collapsedResourceNames) {
if (collapsedResourceNames.getNoCollapseResourceTypesCount() == 0) {
return ImmutableList.of();
}
ImmutableSet<String> excludedTypes =
ImmutableSet.copyOf(collapsedResourceNames.getNoCollapseResourceTypesList());
return bundle.getModules().values().stream()
.filter(bundleModule -> bundleModule.getResourceTable().isPresent())
.map(bundleModule -> bundleModule.getResourceTable().get())
.flatMap(resourceTable -> resourceTable.getPackageList().stream())
.flatMap(resourcePackage -> resourcePackage.getTypeList().stream())
.filter(type -> excludedTypes.contains(type.getName()))
.flatMap(
type ->
type.getEntryList().stream()
.map(
entry ->
ResourceTypeAndName.newBuilder()
.setName(entry.getName())
.setType(type.getName())
.build()))
.collect(toImmutableList());
}
}
Loading

0 comments on commit 8ab1a9f

Please sign in to comment.