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);
}
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();
}
}
}
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);
}
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);
}
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));
}
Aggregations