本文整理了Java中com.android.tools.build.bundletool.io.ZipBuilder.addFileWithProtoContent()
方法的一些代码示例,展示了ZipBuilder.addFileWithProtoContent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipBuilder.addFileWithProtoContent()
方法的具体详情如下:
包路径:com.android.tools.build.bundletool.io.ZipBuilder
类名称:ZipBuilder
方法名:addFileWithProtoContent
[英]Lazily creates a file at the specified path containing the given proto message in binary form.
Will throw an exception if the path is already taken.
[中]惰性地在指定路径创建一个文件,其中包含二进制形式的给定proto消息。
如果路径已被占用,将引发异常。
代码示例来源:origin: google/bundletool
@Override
public void setTableOfContentsFile(BuildApksResult tableOfContentsProto) {
apkSetZipBuilder.addFileWithProtoContent(
ZipPath.create(TABLE_OF_CONTENTS_FILE), tableOfContentsProto);
}
代码示例来源:origin: google/bundletool
private static ZipBuilder createBasicZipBuilderWithManifest(BundleConfig config) {
return createBasicZipBuilder(config)
.addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST);
}
}
代码示例来源:origin: google/bundletool
.ifPresent(
resourceTable ->
zipBuilder.addFileWithProtoContent(
SpecialModuleEntry.RESOURCE_TABLE.getPath(), resourceTable));
zipBuilder.addFileWithProtoContent(
ZipPath.create(MANIFEST_FILENAME), split.getAndroidManifest().getManifestRoot().getProto());
代码示例来源:origin: google/bundletool
private Path createSimpleBaseModule() throws IOException {
return new ZipBuilder()
.addFileWithProtoContent(
ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME))
.writeTo(tmpDir.resolve("base.zip"));
}
代码示例来源:origin: google/bundletool
public static Path createApksArchiveFile(BuildApksResult result, Path location) throws Exception {
ZipBuilder archiveBuilder = new ZipBuilder();
result.getVariantList().stream()
.flatMap(variant -> variant.getApkSetList().stream())
.flatMap(apkSet -> apkSet.getApkDescriptionList().stream())
.forEach(
apkDesc ->
archiveBuilder.addFileWithContent(ZipPath.create(apkDesc.getPath()), DUMMY_BYTES));
archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), result);
return archiveBuilder.writeTo(location);
}
代码示例来源:origin: google/bundletool
private Path buildSimpleModule(String moduleName) throws IOException {
ManifestMutator[] manifestMutators =
moduleName.equals("base")
? new ManifestMutator[0]
: new ManifestMutator[] {withSplitId(moduleName)};
return new ZipBuilder()
.addFileWithProtoContent(
ZipPath.create("manifest/AndroidManifest.xml"),
androidManifest(PKG_NAME, manifestMutators))
.writeTo(FileUtils.getRandomFilePath(tmp, moduleName, ".zip"));
}
代码示例来源:origin: google/bundletool
@Test
public void testMultipleModules() throws Exception {
createBasicZipBuilder(BUNDLE_CONFIG)
.addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST)
.addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT)
.addFileWithContent(ZipPath.create("base/assets/file.txt"), DUMMY_CONTENT)
.addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), MANIFEST)
.addFileWithContent(ZipPath.create("detail/assets/file.txt"), DUMMY_CONTENT)
.writeTo(bundleFile);
AppBundle appBundle = AppBundle.buildFromZip(new ZipFile(bundleFile.toFile()));
assertThat(appBundle.getFeatureModules().keySet())
.containsExactly(BundleModuleName.create("base"), BundleModuleName.create("detail"));
}
代码示例来源:origin: google/bundletool
new ZipBuilder()
.addFileWithContent(ZipPath.create("BundleConfig.pb"), BUNDLE_CONFIG.toByteArray())
.addFileWithProtoContent(
ZipPath.create("moduleX/manifest/AndroidManifest.xml"),
androidManifest("com.test.app", withSplitId("moduleX")))
.addFileWithProtoContent(
ZipPath.create("moduleX/assets.pb"), Assets.getDefaultInstance())
.addFileWithProtoContent(
ZipPath.create("moduleX/native.pb"), NativeLibraries.getDefaultInstance())
.addFileWithProtoContent(
ZipPath.create("moduleX/resources.pb"), ResourceTable.getDefaultInstance())
.addFileWithContent(ZipPath.create("moduleX/res/drawable/icon.png"), DUMMY_CONTENT)
.addFileWithContent(ZipPath.create("moduleX/lib/x86/libX.so"), DUMMY_CONTENT)
.addFileWithProtoContent(
ZipPath.create("moduleY/manifest/AndroidManifest.xml"),
androidManifest("com.test.app", withSplitId("moduleY")))
代码示例来源:origin: google/bundletool
@Test
public void baseAndAssetModule_fromZipFile_areSeparated() throws Exception {
createBasicZipBuilder(BUNDLE_CONFIG)
.addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST)
.addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT)
.addFileWithContent(ZipPath.create("base/assets/file.txt"), DUMMY_CONTENT)
.addFileWithProtoContent(
ZipPath.create("remote_assets/manifest/AndroidManifest.xml"), REMOTE_ASSET_MANIFEST)
.addFileWithContent(ZipPath.create("remote_assets/assets/file.txt"), DUMMY_CONTENT)
.writeTo(bundleFile);
AppBundle appBundle = AppBundle.buildFromZip(new ZipFile(bundleFile.toFile()));
assertThat(appBundle.getFeatureModules().keySet())
.containsExactly(BundleModuleName.create("base"));
assertThat(appBundle.getAssetModules().keySet())
.containsExactly(BundleModuleName.create("remote_assets"));
}
代码示例来源:origin: google/bundletool
@Test
public void validateBundle_invokesSubValidatorsInSequence() throws Exception {
Path bundlePath =
new ZipBuilder()
.addFileWithContent(ZipPath.create("BundleConfig.pb"), BUNDLE_CONFIG.toByteArray())
.addFileWithProtoContent(
ZipPath.create("moduleX/manifest/AndroidManifest.xml"),
androidManifest("com.test.app", withSplitId("moduleX")))
.addFileWithContent(ZipPath.create("moduleX/assets/file.txt"), DUMMY_CONTENT)
.addFileWithProtoContent(
ZipPath.create("moduleY/manifest/AndroidManifest.xml"),
androidManifest("com.test.app", withSplitId("moduleY")))
.addFileWithContent(ZipPath.create("moduleY/assets/file.txt"), DUMMY_CONTENT)
.writeTo(tempFolder.resolve("bundle.aab"));
AppBundle bundle = AppBundle.buildFromZip(new ZipFile(bundlePath.toFile()));
ImmutableList<BundleModule> bundleFeatureModules =
ImmutableList.copyOf(bundle.getFeatureModules().values());
new ValidatorRunner(ImmutableList.of(validator, validator2)).validateBundle(bundle);
InOrder order = Mockito.inOrder(validator, validator2);
order.verify(validator).validateBundle(eq(bundle));
order.verify(validator).validateAllModules(eq(bundleFeatureModules));
order.verify(validator).validateModule(anyObject());
order.verify(validator, atLeastOnce()).validateModuleFile(anyObject());
order.verify(validator2).validateBundle(eq(bundle));
order.verify(validator2).validateAllModules(eq(bundleFeatureModules));
order.verify(validator2).validateModule(anyObject());
order.verify(validator2, atLeastOnce()).validateModuleFile(anyObject());
order.verifyNoMoreInteractions();
}
代码示例来源:origin: google/bundletool
Path module =
new ZipBuilder()
.addFileWithProtoContent(
ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME))
.addFileWithContent(ZipPath.create("dex/classes.dex"), new byte[8])
.addFileWithContent(ZipPath.create("res/raw/hello.png"), new byte[8])
.addFileWithProtoContent(
ZipPath.create("resources.pb"),
new ResourceTableBuilder()
代码示例来源:origin: google/bundletool
@Test
public void runsResourceTableValidator_resourceTableReferencingNonExistingFile_throws()
throws Exception {
ResourceTable resourceTable =
new ResourceTableBuilder()
.addPackage(PKG_NAME)
.addDrawableResource("icon", "res/drawable/icon.png")
.build();
Path module =
new ZipBuilder()
.addFileWithProtoContent(ZipPath.create("resources.pb"), resourceTable)
.addFileWithProtoContent(
ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME))
.writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand command =
BuildBundleCommand.builder()
.setOutputPath(bundlePath)
.setModulesPaths(ImmutableList.of(module))
.build();
ValidationException exception =
assertThrows(ValidationException.class, () -> command.execute());
assertThat(exception).hasMessageThat().contains("contains references to non-existing files");
}
代码示例来源:origin: google/bundletool
@Test
public void runsBundleFilesValidator_rogueFileInModuleRoot_throws() throws Exception {
Path module =
new ZipBuilder()
.addFileWithContent(ZipPath.create("rogue.txt"), "".getBytes(UTF_8))
.addFileWithProtoContent(
ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME))
.writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand command =
BuildBundleCommand.builder()
.setOutputPath(bundlePath)
.setModulesPaths(ImmutableList.of(module))
.build();
ValidationException exception =
assertThrows(ValidationException.class, () -> command.execute());
assertThat(exception)
.hasMessageThat()
.contains("Module files can be only in pre-defined directories");
}
代码示例来源:origin: google/bundletool
DUMMY_BYTES,
archiveBuilder.addFileWithProtoContent(
ZipPath.create("toc.pb"), BuildApksResult.newBuilder().addAllVariant(variants).build());
Path apksArchiveFile = archiveBuilder.writeTo(tmpDir.resolve("bundle.apks"));
代码示例来源:origin: google/bundletool
@Test
public void nativeLibrariesPresent_abiTargetingIsPresent() throws Exception {
Path moduleWithAbi =
new ZipBuilder()
.addFileWithContent(ZipPath.create("lib/x86/libfast.so"), "native data".getBytes(UTF_8))
.addFileWithContent(
ZipPath.create("lib/x86/libfaster.so"), "native data".getBytes(UTF_8))
.addFileWithProtoContent(
ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME))
.writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand.builder()
.setOutputPath(bundlePath)
.setModulesPaths(ImmutableList.of(moduleWithAbi))
.build()
.execute();
ZipFile bundle = new ZipFile(bundlePath.toFile());
assertThat(bundle).hasFile("base/native.pb");
NativeLibraries actualTargeting =
NativeLibraries.parseFrom(bundle.getInputStream(new ZipEntry("base/native.pb")));
NativeLibraries expectedTargeting =
NativeLibraries.newBuilder()
.addDirectory(
TargetedNativeDirectory.newBuilder()
.setPath("lib/x86")
.setTargeting(
NativeDirectoryTargeting.newBuilder()
.setAbi(Abi.newBuilder().setAlias(X86))))
.build();
Truth.assertThat(actualTargeting).isEqualTo(expectedTargeting);
}
代码示例来源:origin: google/bundletool
.addFileWithContent(ZipPath.create("dex/classes.dex"), "dex".getBytes(UTF_8))
.addFileWithContent(ZipPath.create("lib/x86/libX.so"), "native".getBytes(UTF_8))
.addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest)
.addFileWithContent(ZipPath.create("res/drawable/icon.png"), "image".getBytes(UTF_8))
.addFileWithContent(ZipPath.create("root/anything2.dat"), "any2".getBytes(UTF_8))
.addFileWithProtoContent(ZipPath.create("resources.pb"), resourceTable)
.writeTo(tmpDir.resolve("base.zip"));
代码示例来源:origin: google/bundletool
.addFileWithContent(
ZipPath.create("apex/armeabi-v7a.img"), "armeabi-v7a".getBytes(UTF_8))
.addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest)
.addFileWithContent(
ZipPath.create("root/apex_manifest.json"), "manifest".getBytes(UTF_8))
代码示例来源:origin: google/bundletool
archiveBuilder.addFileWithContent(ZipPath.create("preL-ldpi.apk"), new byte[1000]);
archiveBuilder.addFileWithContent(ZipPath.create("preL-mdpi.apk"), new byte[10]);
archiveBuilder.addFileWithProtoContent(
ZipPath.create("toc.pb"),
BuildApksResult.newBuilder()
代码示例来源:origin: google/bundletool
"any2".getBytes(UTF_8))
.addFileWithContent(ZipPath.create("dex/classes.dex"), "dex".getBytes(UTF_8))
.addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest)
.writeTo(tmpDir.resolve("base.zip"));
代码示例来源:origin: google/bundletool
archiveBuilder.addFileWithContent(ZipPath.create("base-master.apk"), DUMMY_BYTES);
archiveBuilder.addFileWithContent(ZipPath.create("preL.apk"), new byte[10000]);
archiveBuilder.addFileWithProtoContent(
ZipPath.create("toc.pb"),
BuildApksResult.newBuilder().addVariant(lVariant).addVariant(preLVariant).build());
内容来源于网络,如有侵权,请联系作者删除!