Skip to content

Commit

Permalink
Prepare for release 1.13.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
sopo-c committed Nov 14, 2022
1 parent 8ab1a9f commit db27934
Show file tree
Hide file tree
Showing 93 changed files with 3,907 additions and 160 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.0](https://github.com/google/bundletool/releases)
Latest release: [1.13.1](https://github.com/google/bundletool/releases)
1 change: 1 addition & 0 deletions dex_src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Contains the source-code for any .dex files in bundletool.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version = 1.13.0
release_version = 1.13.1
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public enum OutputFormat {
private static final Flag<ImmutableSet<SystemApkOption>> SYSTEM_APK_OPTIONS =
Flag.enumSet("system-apk-options", SystemApkOption.class);
private static final Flag<Integer> DEVICE_TIER_FLAG = Flag.nonNegativeInteger("device-tier");
private static final Flag<String> COUNTRY_SET_FLAG = Flag.string("country-set");

private static final Flag<Boolean> VERBOSE_FLAG = Flag.booleanFlag("verbose");

Expand Down Expand Up @@ -238,6 +239,8 @@ public enum OutputFormat {

public abstract Optional<Integer> getDeviceTier();

public abstract Optional<String> getCountrySet();

public abstract ImmutableSet<SystemApkOption> getSystemApkOptions();

public abstract boolean getGenerateOnlyForConnectedDevice();
Expand Down Expand Up @@ -389,6 +392,12 @@ public Builder setDeviceSpec(Path deviceSpecFile) {
*/
public abstract Builder setDeviceTier(Integer deviceTier);

/**
* Sets the country set to use for APK matching. This will override the country set of the given
* device spec.
*/
public abstract Builder setCountrySet(String countrySet);

/** Sets options to generated APKs in system mode. */
public abstract Builder setSystemApkOptions(ImmutableSet<SystemApkOption> options);

Expand Down Expand Up @@ -652,6 +661,16 @@ public BuildApksCommand build() {
.build();
}

if (command.getCountrySet().isPresent()
&& !command.getGenerateOnlyForConnectedDevice()
&& !command.getDeviceSpec().isPresent()) {
throw InvalidCommandException.builder()
.withInternalMessage(
"Setting --country-set requires using either the --connected-device or the"
+ " --device-spec flag.")
.build();
}

if (command.getOutputFormat().equals(APK_SET)) {
if (!APK_SET_ARCHIVE_EXTENSION.equals(
MoreFiles.getFileExtension(command.getOutputFile()))) {
Expand Down Expand Up @@ -776,6 +795,7 @@ static BuildApksCommand fromFlags(
.map(deviceSpecParser)
.ifPresent(buildApksCommand::setDeviceSpec);
DEVICE_TIER_FLAG.getValue(flags).ifPresent(buildApksCommand::setDeviceTier);
COUNTRY_SET_FLAG.getValue(flags).ifPresent(buildApksCommand::setCountrySet);
MODULES_FLAG.getValue(flags).ifPresent(buildApksCommand::setModules);
VERBOSE_FLAG.getValue(flags).ifPresent(buildApksCommand::setVerbose);
P7ZIP_PATH_FLAG
Expand Down Expand Up @@ -1356,7 +1376,7 @@ public static CommandHelp help() {
.setDescription(
"If set, will generate APK Set optimized for the connected device. The "
+ "generated APK Set will only be installable on that specific class of "
+ "devices. This flag should be only be set with --%s=%s flag.",
+ "devices. This flag should only be set with --%s=%s flag.",
BUILD_MODE_FLAG.getName(), DEFAULT.getLowerCaseName())
.build())
.addFlag(
Expand Down Expand Up @@ -1399,12 +1419,24 @@ public static CommandHelp help() {
.setExampleValue("low")
.setOptional(true)
.setDescription(
"Device tier to use for APK matching. This flag should be only be set with"
"Device tier to use for APK matching. This flag should only be set with"
+ " --%s or --%s flags. If a device spec with a device tier is provided,"
+ " the value specified here will override the value set in the device"
+ " spec.",
DEVICE_SPEC_FLAG.getName(), CONNECTED_DEVICE_FLAG.getName())
.build())
.addFlag(
FlagDescription.builder()
.setFlagName(COUNTRY_SET_FLAG.getName())
.setExampleValue("country_set_name")
.setOptional(true)
.setDescription(
"Country set to use for APK matching. This flag should only be set with"
+ " --%s or --%s flags. If a device spec with a country set is provided,"
+ " the value specified here will override the value set in the device"
+ " spec.",
DEVICE_SPEC_FLAG.getName(), CONNECTED_DEVICE_FLAG.getName())
.build())
.addFlag(
FlagDescription.builder()
.setFlagName(FUSE_ONLY_DEVICE_MATCHING_MODULES_FLAG.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.android.tools.build.bundletool.optimizations.OptimizationsMerger;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.protobuf.Int32Value;
import com.google.protobuf.StringValue;
import dagger.Module;
import dagger.Provides;
import java.io.PrintStream;
Expand Down Expand Up @@ -153,6 +154,15 @@ static Optional<DeviceSpec> provideDeviceSpec(BuildApksCommand command) {
.setDeviceTier(Int32Value.of(command.getDeviceTier().get()))
.build());
}
if (command.getCountrySet().isPresent()) {
checkState(deviceSpec.isPresent(), "Country set specified but no device was provided");
deviceSpec =
deviceSpec.map(
spec ->
spec.toBuilder()
.setCountrySet(StringValue.of(command.getCountrySet().get()))
.build());
}
return deviceSpec;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.android.tools.build.bundletool.commands;

import static com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE;
import static com.android.tools.build.bundletool.device.DeviceTargetingConfigEvaluator.getMatchingCountrySet;
import static com.android.tools.build.bundletool.device.DeviceTargetingConfigEvaluator.getMatchingDeviceGroups;
import static com.android.tools.build.bundletool.device.DeviceTargetingConfigEvaluator.getSelectedDeviceTier;
import static com.android.tools.build.bundletool.model.utils.SdkToolsLocator.ANDROID_HOME_VARIABLE;
Expand Down Expand Up @@ -74,6 +75,8 @@ public abstract class EvaluateDeviceTargetingConfigCommand {

private static final Flag<String> DEVICE_ID_FLAG = Flag.string("device-id");

private static final Flag<String> COUNTRY_CODE_FLAG = Flag.string("country-code");

private static final SystemEnvironmentProvider DEFAULT_PROVIDER =
new DefaultSystemEnvironmentProvider();

Expand All @@ -96,6 +99,8 @@ public abstract class EvaluateDeviceTargetingConfigCommand {

public abstract Optional<String> getDeviceId();

public abstract Optional<String> getCountryCode();

abstract Optional<Path> getAdbPath();

static Builder builder() {
Expand All @@ -114,6 +119,8 @@ abstract static class Builder {

abstract Builder setDeviceId(Optional<String> id);

abstract Builder setCountryCode(String countryCode);

abstract EvaluateDeviceTargetingConfigCommand build();

abstract Builder setAdbPath(Path adbPath);
Expand Down Expand Up @@ -177,6 +184,9 @@ public static EvaluateDeviceTargetingConfigCommand fromFlags(
.setConnectedDeviceMode(true)
.setDeviceId(DEVICE_ID_FLAG.getValue(flags));
}
COUNTRY_CODE_FLAG
.getValue(flags)
.ifPresent(evaluateDeviceTargetingConfigCommandBuilder::setCountryCode);

return evaluateDeviceTargetingConfigCommandBuilder.build();
}
Expand All @@ -188,6 +198,9 @@ public void execute(PrintStream out) throws IOException, TimeoutException {
DeviceTierConfig config = configBuilder.build();

DeviceTierConfigValidator.validateDeviceTierConfig(config);
if (getCountryCode().isPresent()) {
DeviceTierConfigValidator.validateCountryCode(getCountryCode().get());
}

DeviceProperties.Builder devicePropertiesBuilder = DeviceProperties.newBuilder();
if (this.getDevicePropertiesPath().isPresent()) {
Expand All @@ -202,6 +215,9 @@ public void execute(PrintStream out) throws IOException, TimeoutException {

printTier(getSelectedDeviceTier(config, deviceProperties), out);
printGroups(getMatchingDeviceGroups(config, deviceProperties), out);
if (getCountryCode().isPresent()) {
printCountrySet(getMatchingCountrySet(config, getCountryCode().get()), out);
}
}
}

Expand Down Expand Up @@ -248,6 +264,10 @@ private void printGroups(ImmutableSet<DeviceGroup> deviceGroups, PrintStream out
}
}

private void printCountrySet(String countrySet, PrintStream out) {
out.println("Country Set: '" + countrySet + "'");
}

public static CommandHelp help() {
return CommandHelp.builder()
.setCommandName(COMMAND_NAME)
Expand Down Expand Up @@ -300,6 +320,16 @@ public static CommandHelp help() {
+ "device or emulator is connected. Used only if %s flag is set.",
ANDROID_SERIAL_VARIABLE, CONNECTED_DEVICE_FLAG)
.build())
.addFlag(
FlagDescription.builder()
.setFlagName(COUNTRY_CODE_FLAG.getName())
.setExampleValue("VN")
.setOptional(true)
.setDescription(
"An ISO 3166 alpha-2 format country code for the country of user account on the"
+ " device. This will be used to derive corresponding country set from"
+ " device targeting configuration.")
.build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteStreams;
import com.google.protobuf.Int32Value;
import com.google.protobuf.StringValue;
import com.google.protobuf.util.JsonFormat;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -94,6 +95,8 @@ public abstract class ExtractApksCommand {

public abstract Optional<ImmutableSet<String>> getModules();

public abstract boolean getIncludeInstallTimeAssetModules();

/** Gets whether instant APKs should be extracted. */
public abstract boolean getInstant();

Expand All @@ -103,7 +106,8 @@ public abstract class ExtractApksCommand {
public static Builder builder() {
return new AutoValue_ExtractApksCommand.Builder()
.setInstant(false)
.setIncludeMetadata(false);
.setIncludeMetadata(false)
.setIncludeInstallTimeAssetModules(true);
}

/** Builder for the {@link ExtractApksCommand}. */
Expand All @@ -119,8 +123,20 @@ public Builder setDeviceSpec(Path deviceSpecPath) {

public abstract Builder setOutputDirectory(Path outputDirectory);

/**
* Sets the required modules to extract.
*
* <p>All install-time feature modules and asset modules are extracted by default. You can
* exclude install-time asset modules by passing {@code false} to {@link
* #setIncludeInstallTimeAssetModules}.
*
* <p>"_ALL_" extracts all modules.
*/
public abstract Builder setModules(ImmutableSet<String> modules);

/** Whether to extract install-time asset modules (default = true). */
public abstract Builder setIncludeInstallTimeAssetModules(boolean shouldInclude);

/**
* Sets whether instant APKs should be extracted.
*
Expand Down Expand Up @@ -195,6 +211,7 @@ ImmutableList<Path> execute(PrintStream output) {
new ApkMatcher(
deviceSpec,
requestedModuleNames,
getIncludeInstallTimeAssetModules(),
getInstant(),
/* ensureDensityAndAbiApksMatched= */ true);
ImmutableList<GeneratedApk> generatedApks = apkMatcher.getMatchingApks(toc);
Expand Down Expand Up @@ -350,6 +367,18 @@ private static DeviceSpec applyDefaultsToDeviceSpec(DeviceSpec deviceSpec, Build
.orElse(0);
builder.setDeviceTier(Int32Value.of(defaultDeviceTier));
}
if (!deviceSpec.hasCountrySet()) {
String defaultCountrySet =
toc.getDefaultTargetingValueList().stream()
.filter(
defaultTargetingValue ->
defaultTargetingValue.getDimension().equals(Value.COUNTRY_SET))
.map(DefaultTargetingValue::getDefaultValue)
.filter(defaultValue -> !defaultValue.isEmpty())
.collect(toOptional())
.orElse("");
builder.setCountrySet(StringValue.of(defaultCountrySet));
}
if (!deviceSpec.hasSdkRuntime()) {
builder
.getSdkRuntimeBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.io.MoreFiles;
import com.google.protobuf.Int32Value;
import com.google.protobuf.StringValue;
import com.google.protobuf.util.JsonFormat;
import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -59,6 +60,7 @@ public abstract class GetDeviceSpecCommand {
private static final Flag<Integer> DEVICE_TIER_FLAG = Flag.nonNegativeInteger("device-tier");
private static final Flag<ImmutableSet<String>> DEVICE_GROUPS_FLAG =
Flag.stringSet("device-groups");
private static final Flag<String> COUNTRY_SET_FLAG = Flag.string("country-set");

private static final SystemEnvironmentProvider DEFAULT_PROVIDER =
new DefaultSystemEnvironmentProvider();
Expand All @@ -79,6 +81,8 @@ public abstract class GetDeviceSpecCommand {

public abstract Optional<ImmutableSet<String>> getDeviceGroups();

public abstract Optional<String> getCountrySet();

public static Builder builder() {
return new AutoValue_GetDeviceSpecCommand.Builder().setOverwriteOutput(false);
}
Expand Down Expand Up @@ -107,6 +111,8 @@ public abstract static class Builder {

public abstract Builder setDeviceGroups(ImmutableSet<String> deviceGroups);

public abstract Builder setCountrySet(String countrySet);

abstract GetDeviceSpecCommand autoBuild();

public GetDeviceSpecCommand build() {
Expand Down Expand Up @@ -144,6 +150,7 @@ public static GetDeviceSpecCommand fromFlags(

DEVICE_TIER_FLAG.getValue(flags).ifPresent(builder::setDeviceTier);
DEVICE_GROUPS_FLAG.getValue(flags).ifPresent(builder::setDeviceGroups);
COUNTRY_SET_FLAG.getValue(flags).ifPresent(builder::setCountrySet);
flags.checkNoUnknownFlags();

return builder.build();
Expand All @@ -167,6 +174,10 @@ public DeviceSpec execute() {
if (getDeviceGroups().isPresent()) {
deviceSpec = deviceSpec.toBuilder().addAllDeviceGroups(getDeviceGroups().get()).build();
}
if (getCountrySet().isPresent()) {
deviceSpec =
deviceSpec.toBuilder().setCountrySet(StringValue.of(getCountrySet().get())).build();
}
writeDeviceSpecToFile(deviceSpec, getOutputPath());
return deviceSpec;
}
Expand Down Expand Up @@ -255,6 +266,17 @@ public static CommandHelp help() {
+ " This flag is only relevant if the bundle uses device group targeting"
+ " in conditional modules and should be set in that case.")
.build())
.addFlag(
FlagDescription.builder()
.setFlagName(COUNTRY_SET_FLAG.getName())
.setExampleValue("country_set_name")
.setOptional(true)
.setDescription(
"Country set for the user account on the device. This value will be"
+ " used to match the correct country set targeted APKs to this device."
+ " This flag is only relevant if the bundle uses country set targeting,"
+ " and should be set in that case.")
.build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public static GetSizeSubcommand fromString(String subCommand) {
Dimension.SCREEN_DENSITY,
Dimension.TEXTURE_COMPRESSION_FORMAT,
Dimension.DEVICE_TIER,
Dimension.COUNTRY_SET,
Dimension.SDK_RUNTIME);

public abstract Path getApksArchivePath();
Expand Down
Loading

0 comments on commit db27934

Please sign in to comment.