Search in sources :

Example 1 with SdkBundle

use of com.android.tools.build.bundletool.model.SdkBundle in project bundletool by google.

the class BuildApksCommand method validateSdkBundles.

private void validateSdkBundles(Closer closer) throws IOException {
    SdkBundleValidator sdkBundleValidator = SdkBundleValidator.create();
    ImmutableSet.Builder<ZipFile> sdkBundleZipsBuilder = ImmutableSet.builder();
    for (Path sdkBundlePath : getRuntimeEnabledSdkBundlePaths()) {
        sdkBundleZipsBuilder.add(closer.register(new ZipFile(sdkBundlePath.toFile())));
    }
    ImmutableSet<ZipFile> sdkBundleZips = sdkBundleZipsBuilder.build();
    sdkBundleZips.forEach(sdkBundleValidator::validateFile);
    ImmutableSet<SdkBundle> sdkBundles = sdkBundleZips.stream().map(sdkBundleZip -> SdkBundle.buildFromZip(sdkBundleZip, /* versionCode= */
    0)).collect(toImmutableSet());
    sdkBundles.forEach(sdkBundleValidator::validate);
}
Also used : Path(java.nio.file.Path) RandomAccessFile(java.io.RandomAccessFile) DataSource(com.android.apksig.util.DataSource) Arrays(java.util.Arrays) SYSTEM(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM) UNIVERSAL(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.UNIVERSAL) DaggerAppBundlePreprocessorComponent(com.android.tools.build.bundletool.preprocessors.DaggerAppBundlePreprocessorComponent) AppBundlePreprocessorManager(com.android.tools.build.bundletool.preprocessors.AppBundlePreprocessorManager) SYSTEM_PATH_VARIABLE(com.android.tools.build.bundletool.model.utils.SdkToolsLocator.SYSTEM_PATH_VARIABLE) DeviceSpec(com.android.bundle.Devices.DeviceSpec) TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleValidator(com.android.tools.build.bundletool.validation.SdkBundleValidator) Flag(com.android.tools.build.bundletool.flags.Flag) ZipFile(java.util.zip.ZipFile) FilePreconditions.checkFileHasExtension(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileHasExtension) Path(java.nio.file.Path) SourceStamp(com.android.tools.build.bundletool.model.SourceStamp) SigningConfigurationProvider(com.android.tools.build.bundletool.model.SigningConfigurationProvider) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ZipException(java.util.zip.ZipException) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) SigningCertificateLineage(com.android.apksig.SigningCertificateLineage) Aapt2Command(com.android.tools.build.bundletool.androidtools.Aapt2Command) ParsedFlags(com.android.tools.build.bundletool.flags.ParsedFlags) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) DIRECTORY(com.android.tools.build.bundletool.commands.BuildApksCommand.OutputFormat.DIRECTORY) Executors(java.util.concurrent.Executors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) KeystoreProperties(com.android.tools.build.bundletool.model.KeystoreProperties) UncheckedIOException(java.io.UncheckedIOException) ByteOrder(java.nio.ByteOrder) SystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.SystemEnvironmentProvider) Password(com.android.tools.build.bundletool.model.Password) SignerConfig(com.android.tools.build.bundletool.model.SignerConfig) AppBundleRecompressor(com.android.tools.build.bundletool.preprocessors.AppBundleRecompressor) SubValidator(com.android.tools.build.bundletool.validation.SubValidator) AutoValue(com.google.auto.value.AutoValue) APK_SET(com.android.tools.build.bundletool.commands.BuildApksCommand.OutputFormat.APK_SET) FilePreconditions.checkFileDoesNotExist(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileDoesNotExist) Optional(java.util.Optional) FilePreconditions.checkFileExistsAndReadable(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndReadable) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) OptimizationDimension(com.android.tools.build.bundletool.model.OptimizationDimension) ApkModifier(com.android.tools.build.bundletool.model.ApkModifier) ApkListener(com.android.tools.build.bundletool.model.ApkListener) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) ImmutableList(com.google.common.collect.ImmutableList) DefaultSystemEnvironmentProvider(com.android.tools.build.bundletool.model.utils.DefaultSystemEnvironmentProvider) Closer(com.google.common.io.Closer) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ApkFormatException(com.android.apksig.apk.ApkFormatException) AdbServer(com.android.tools.build.bundletool.device.AdbServer) AppBundleValidator(com.android.tools.build.bundletool.validation.AppBundleValidator) PrintStream(java.io.PrintStream) ANDROID_HOME_VARIABLE(com.android.tools.build.bundletool.model.utils.SdkToolsLocator.ANDROID_HOME_VARIABLE) FilePreconditions.checkFileExistsAndExecutable(com.android.tools.build.bundletool.model.utils.files.FilePreconditions.checkFileExistsAndExecutable) DeviceSpecParser(com.android.tools.build.bundletool.device.DeviceSpecParser) Files(java.nio.file.Files) ARCHIVE(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.ARCHIVE) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Ascii(com.google.common.base.Ascii) ANDROID_SERIAL_VARIABLE(com.android.tools.build.bundletool.commands.CommandUtils.ANDROID_SERIAL_VARIABLE) IOException(java.io.IOException) DataSources(com.android.apksig.util.DataSources) DEFAULT(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.DEFAULT) File(java.io.File) P7ZipCommand(com.android.tools.build.bundletool.androidtools.P7ZipCommand) MoreFiles(com.google.common.io.MoreFiles) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) FlagDescription(com.android.tools.build.bundletool.commands.CommandHelp.FlagDescription) AppBundle(com.android.tools.build.bundletool.model.AppBundle) FileUtils(com.android.tools.build.bundletool.model.utils.files.FileUtils) CommandDescription(com.android.tools.build.bundletool.commands.CommandHelp.CommandDescription) ZipReader(com.android.tools.build.bundletool.io.ZipReader) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ZipFile(java.util.zip.ZipFile) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleValidator(com.android.tools.build.bundletool.validation.SdkBundleValidator)

Example 2 with SdkBundle

use of com.android.tools.build.bundletool.model.SdkBundle in project bundletool by google.

the class BuildSdkApksCommand method execute.

public void execute() {
    validateInput();
    try (ZipFile bundleZip = new ZipFile(getSdkBundlePath().toFile());
        ZipReader zipReader = ZipReader.createFromFile(getSdkBundlePath());
        TempDirectory tempDir = new TempDirectory(getClass().getSimpleName())) {
        SdkBundleValidator bundleValidator = SdkBundleValidator.create();
        bundleValidator.validateFile(bundleZip);
        SdkBundle sdkBundle = SdkBundle.buildFromZip(bundleZip, getVersionCode());
        bundleValidator.validate(sdkBundle);
        DaggerBuildSdkApksManagerComponent.builder().setBuildSdkApksCommand(this).setTempDirectory(tempDir).setSdkBundle(sdkBundle).setZipReader(zipReader).setUseBundleCompression(false).build().create().execute();
    } 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);
    } finally {
        if (isExecutorServiceCreatedByBundleTool()) {
            getExecutorService().shutdown();
        }
    }
}
Also used : TempDirectory(com.android.tools.build.bundletool.io.TempDirectory) ZipFile(java.util.zip.ZipFile) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleValidator(com.android.tools.build.bundletool.validation.SdkBundleValidator) ZipReader(com.android.tools.build.bundletool.io.ZipReader) ZipException(java.util.zip.ZipException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 3 with SdkBundle

use of com.android.tools.build.bundletool.model.SdkBundle in project bundletool by google.

the class BuildSdkApksManagerTest method sdkVersionInformationIsSet.

@Test
public void sdkVersionInformationIsSet() throws Exception {
    SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withSdkLibraryElement("100"), withMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME, "132"))).build()).setVersionCode(99).build();
    execute(sdkBundle);
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    SdkVersionInformation version = result.getVersion();
    assertThat(version.getVersionCode()).isEqualTo(99);
    assertThat(version.getMajor()).isEqualTo(100);
    assertThat(version.getPatch()).isEqualTo(132);
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) SdkVersionInformation(com.android.bundle.Commands.SdkVersionInformation) ZipFile(java.util.zip.ZipFile) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) Test(org.junit.Test)

Example 4 with SdkBundle

use of com.android.tools.build.bundletool.model.SdkBundle in project bundletool by google.

the class BuildSdkApksManagerTest method sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged.

@Test
public void sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged() throws Exception {
    SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withMinSdkVersion(SDK_SANDBOX_MIN_VERSION + 5), withSdkLibraryElement("20"), withMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME, "12"))).build()).build();
    execute(sdkBundle);
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    Variant variant = result.getVariant(0);
    ApkDescription apkDescription = variant.getApkSet(0).getApkDescription(0);
    File apkFile = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), tmpDir);
    AndroidManifest manifest = extractAndroidManifest(apkFile, tmpDir);
    assertThat(manifest.getMinSdkVersion()).hasValue(SDK_SANDBOX_MIN_VERSION + 5);
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) Variant(com.android.bundle.Commands.Variant) ApkDescription(com.android.bundle.Commands.ApkDescription) ZipFile(java.util.zip.ZipFile) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) TestUtils.extractAndroidManifest(com.android.tools.build.bundletool.testing.TestUtils.extractAndroidManifest) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) ApkSetUtils.extractTocFromSdkApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromSdkApkSetFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) Test(org.junit.Test)

Example 5 with SdkBundle

use of com.android.tools.build.bundletool.model.SdkBundle in project bundletool by google.

the class BuildSdkApksManagerTest method sdkPatchVersionIsSetToDefaultValue.

@Test
public void sdkPatchVersionIsSetToDefaultValue() throws Exception {
    SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withSdkLibraryElement("1181894"))).build()).build();
    execute(sdkBundle);
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    SdkVersionInformation version = result.getVersion();
    assertThat(version.getPatch()).isEqualTo(Long.parseLong(DEFAULT_SDK_PATCH_VERSION));
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) SdkVersionInformation(com.android.bundle.Commands.SdkVersionInformation) ZipFile(java.util.zip.ZipFile) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) Test(org.junit.Test)

Aggregations

SdkBundle (com.android.tools.build.bundletool.model.SdkBundle)7 ZipFile (java.util.zip.ZipFile)6 BuildSdkApksResult (com.android.bundle.Commands.BuildSdkApksResult)4 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)4 SdkBundleBuilder (com.android.tools.build.bundletool.testing.SdkBundleBuilder)4 Test (org.junit.Test)4 Variant (com.android.bundle.Commands.Variant)3 File (java.io.File)3 ApkDescription (com.android.bundle.Commands.ApkDescription)2 SdkVersionInformation (com.android.bundle.Commands.SdkVersionInformation)2 TempDirectory (com.android.tools.build.bundletool.io.TempDirectory)2 ZipReader (com.android.tools.build.bundletool.io.ZipReader)2 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)2 SdkBundleValidator (com.android.tools.build.bundletool.validation.SdkBundleValidator)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 ZipException (java.util.zip.ZipException)2 SigningCertificateLineage (com.android.apksig.SigningCertificateLineage)1 ApkFormatException (com.android.apksig.apk.ApkFormatException)1 DataSource (com.android.apksig.util.DataSource)1