Search in sources :

Example 1 with ExtractedApk

use of com.android.bundle.Commands.ExtractedApk in project bundletool by google.

the class ExtractApksCommand method produceCommandMetadata.

private static void produceCommandMetadata(ImmutableList<GeneratedApk> generatedApks, BuildApksResult toc, Path outputDir) {
    ImmutableList<ExtractedApk> apks = generatedApks.stream().map(apk -> ExtractedApk.newBuilder().setPath(apk.getPath().getFileName().toString()).setModuleName(apk.getModuleName()).setDeliveryType(apk.getDeliveryType()).build()).collect(toImmutableList());
    try {
        JsonFormat.Printer printer = JsonFormat.printer();
        ExtractApksResult.Builder builder = ExtractApksResult.newBuilder();
        if (toc.getLocalTestingInfo().getEnabled()) {
            builder.setLocalTestingInfo(createLocalTestingInfo(toc));
        }
        String metadata = printer.print(builder.addAllApks(apks).build());
        Files.write(outputDir.resolve(METADATA_FILE), metadata.getBytes(UTF_8));
    } catch (IOException e) {
        throw new UncheckedIOException("Error while writing metadata.json.", e);
    }
}
Also used : Value(com.android.bundle.Config.SplitDimension.Value) DeviceSpec(com.android.bundle.Devices.DeviceSpec) FilePreconditions.checkDirectoryExists(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkDirectoryExists) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ExtractedApk(com.android.bundle.Commands.ExtractedApk) Flag(com.android.tools.build.bundletool.flags.Flag) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) LocalTestingPathResolver.resolveLocalTestingPath(com.android.tools.build.bundletool.device.LocalTestingPathResolver.resolveLocalTestingPath) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ParsedFlags(com.android.tools.build.bundletool.flags.ParsedFlags) Logger(java.util.logging.Logger) UncheckedIOException(java.io.UncheckedIOException) DefaultTargetingValue(com.android.bundle.Commands.DefaultTargetingValue) Stream(java.util.stream.Stream) JsonFormat(com.google.protobuf.util.JsonFormat) ExtractApksResult(com.android.bundle.Commands.ExtractApksResult) FileNames(com.android.tools.build.bundletool.model.utils.FileNames) AutoValue(com.google.auto.value.AutoValue) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) LocalTestingInfoForMetadata(com.android.bundle.Commands.LocalTestingInfoForMetadata) FilePreconditions.checkFileExistsAndReadable(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndReadable) BuildApksResult(com.android.bundle.Commands.BuildApksResult) GeneratedApk(com.android.tools.build.bundletool.device.ApkMatcher.GeneratedApk) ResultUtils(com.android.tools.build.bundletool.model.utils.ResultUtils) ImmutableList(com.google.common.collect.ImmutableList) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ApkMatcher(com.android.tools.build.bundletool.device.ApkMatcher) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) Int32Value(com.google.protobuf.Int32Value) DeviceSpecParser(com.android.tools.build.bundletool.device.DeviceSpecParser) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) IOException(java.io.IOException) AssetModuleMetadata(com.android.bundle.Commands.AssetModuleMetadata) IncompatibleDeviceException(com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagDescription(com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FileUtils(com.android.tools.build.bundletool.model.utils.files.FileUtils) CommandDescription(com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription) InputStream(java.io.InputStream) ExtractApksResult(com.android.bundle.Commands.ExtractApksResult) JsonFormat(com.google.protobuf.util.JsonFormat) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ExtractedApk(com.android.bundle.Commands.ExtractedApk)

Aggregations

AssetModuleMetadata (com.android.bundle.Commands.AssetModuleMetadata)1 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)1 BuildApksResult (com.android.bundle.Commands.BuildApksResult)1 DefaultTargetingValue (com.android.bundle.Commands.DefaultTargetingValue)1 ExtractApksResult (com.android.bundle.Commands.ExtractApksResult)1 ExtractedApk (com.android.bundle.Commands.ExtractedApk)1 LocalTestingInfoForMetadata (com.android.bundle.Commands.LocalTestingInfoForMetadata)1 Value (com.android.bundle.Config.SplitDimension.Value)1 DeviceSpec (com.android.bundle.Devices.DeviceSpec)1 CommandDescription (com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription)1 FlagDescription (com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription)1 ApkMatcher (com.android.tools.build.bundletool.device.ApkMatcher)1 GeneratedApk (com.android.tools.build.bundletool.device.ApkMatcher.GeneratedApk)1 DeviceSpecParser (com.android.tools.build.bundletool.device.DeviceSpecParser)1 LocalTestingPathResolver.resolveLocalTestingPath (com.android.tools.build.bundletool.device.LocalTestingPathResolver.resolveLocalTestingPath)1 Flag (com.android.tools.build.bundletool.flags.Flag)1 ParsedFlags (com.android.tools.build.bundletool.flags.ParsedFlags)1 IncompatibleDeviceException (com.android.tools.build.bundletool.model.exceptions.IncompatibleDeviceException)1 InvalidCommandException (com.android.tools.build.bundletool.model.exceptions.InvalidCommandException)1 FileNames (com.android.tools.build.bundletool.model.utils.FileNames)1