use of com.android.bundle.Commands.BuildSdkApksResult in project bundletool by google.
the class ApkSetWriter method zip.
/**
* Creates ApkSet writer which stores all splits as ZIP archive.
*/
static ApkSetWriter zip(Path tempDirectory, Path outputFile) {
return new ApkSetWriter() {
@Override
public Path getSplitsDirectory() {
return tempDirectory;
}
@Override
public void writeApkSet(BuildApksResult toc) throws IOException {
Stream<ApkDescription> apks = toc.getVariantList().stream().flatMap(variant -> variant.getApkSetList().stream()).flatMap(apkSet -> apkSet.getApkDescriptionList().stream());
Stream<ApkDescription> assets = toc.getAssetSliceSetList().stream().flatMap(assetSliceSet -> assetSliceSet.getApkDescriptionList().stream());
ImmutableSet<String> apkRelativePaths = Stream.concat(apks, assets).map(ApkDescription::getPath).sorted().collect(toImmutableSet());
zipApkSet(apkRelativePaths, toc.toByteArray());
}
@Override
public void writeApkSet(BuildSdkApksResult toc) throws IOException {
Stream<ApkDescription> apks = toc.getVariantList().stream().flatMap(variant -> variant.getApkSetList().stream()).flatMap(apkSet -> apkSet.getApkDescriptionList().stream());
ImmutableSet<String> apkRelativePaths = apks.map(ApkDescription::getPath).sorted().collect(toImmutableSet());
zipApkSet(apkRelativePaths, toc.toByteArray());
}
private void zipApkSet(ImmutableSet<String> apkRelativePaths, byte[] tocBytes) throws IOException {
try (ZipArchive zipArchive = new ZipArchive(outputFile)) {
zipArchive.add(new BytesSource(tocBytes, TABLE_OF_CONTENTS_FILE, Deflater.NO_COMPRESSION));
for (String relativePath : apkRelativePaths) {
zipArchive.add(new LargeFileSource(getSplitsDirectory().resolve(relativePath), /* tmpStorage= */
null, relativePath, Deflater.NO_COMPRESSION));
}
}
}
};
}
use of com.android.bundle.Commands.BuildSdkApksResult in project bundletool by google.
the class BuildSdkApksManagerTest method sdkManifestMutation_patchVersionNotSet_defaultPatchVersionAdded.
@Test
public void sdkManifestMutation_patchVersionNotSet_defaultPatchVersionAdded() throws Exception {
SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withSdkLibraryElement("20"))).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.getMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME)).hasValue(DEFAULT_SDK_PATCH_VERSION);
}
use of com.android.bundle.Commands.BuildSdkApksResult in project bundletool by google.
the class BuildSdkApksManagerTest method tocIsCorrect.
@Test
public void tocIsCorrect() throws Exception {
execute(new SdkBundleBuilder().build());
ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
assertThat(result.getVariantCount()).isEqualTo(1);
assertThat(result.getPackageName()).isEqualTo(PACKAGE_NAME);
assertThat(result.getBundletool().getVersion()).isEqualTo(DEFAULT_BUNDLE_CONFIG.getBundletool().getVersion());
}
use of com.android.bundle.Commands.BuildSdkApksResult in project bundletool by google.
the class ApkSerializerManager method serializeSdkApkSet.
/**
* Serialize SDK Bundle APKs.
*/
public void serializeSdkApkSet(ApkSetWriter apkSetWriter, GeneratedApks generatedApks) {
try {
BuildSdkApksResult toc = serializeSdkApkSetContent(apkSetWriter.getSplitsDirectory(), generatedApks);
apkSetWriter.writeApkSet(toc);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations