use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class BuildBundleCommandTest method assetsTargeting_generated.
@Test
public void assetsTargeting_generated() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(true));
Assets assetsConfig = Assets.newBuilder().addDirectory(TargetedAssetsDirectory.newBuilder().setPath("assets").setTargeting(AssetsDirectoryTargeting.getDefaultInstance())).addDirectory(TargetedAssetsDirectory.newBuilder().setPath("assets/texture#tcf_atc/device#tier_0").setTargeting(mergeAssetsTargeting(assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ATC)), assetsDirectoryTargeting(deviceTierTargeting(0))))).build();
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("assets/anything.dat"), "any".getBytes(UTF_8)).addFileWithContent(ZipPath.create("assets/texture#tcf_atc/device#tier_0/file.dat"), "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"));
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
assertThat(bundle).hasFile("base/assets/anything.dat").withContent("any".getBytes(UTF_8));
assertThat(bundle).hasFile("base/assets/texture#tcf_atc/device#tier_0/file.dat").withContent("any2".getBytes(UTF_8));
assertThat(bundle).hasFile("base/dex/classes.dex").withContent("dex".getBytes(UTF_8));
assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/assets.pb").withContent(assetsConfig.toByteArray());
}
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class BuildBundleCommandTest method validApexModule.
@Test
public void validApexModule() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(false));
ImmutableSet<AbiAlias> targetedAbis = ImmutableSet.of(X86_64, X86, ARM64_V8A, ARMEABI_V7A);
ApexImages apexConfig = apexImages(targetedImageWithAlternatives("apex/x86_64.img", X86_64, targetedAbis), targetedImageWithAlternatives("apex/x86.img", X86, targetedAbis), targetedImageWithAlternatives("apex/arm64-v8a.img", ARM64_V8A, targetedAbis), targetedImageWithAlternatives("apex/armeabi-v7a.img", ARMEABI_V7A, targetedAbis));
byte[] apexManifest = "{\"name\": \"com.test.app\"}".getBytes(UTF_8);
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("apex/x86_64.img"), "x86_64".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.img"), "x86".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.img"), "arm64-v8a".getBytes(UTF_8)).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"), apexManifest).writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/apex/x86_64.img").withContent("x86_64".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86.img").withContent("x86".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.img").withContent("arm64-v8a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.img").withContent("armeabi-v7a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/root/apex_manifest.json").withContent(apexManifest);
assertThat(bundle).hasFile("base/apex.pb").withContent(apexConfig.toByteArray());
}
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class BuildBundleCommandTest method validApexModuleWithBuildInfo.
@Test
public void validApexModuleWithBuildInfo() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(false));
ImmutableSet<AbiAlias> targetedAbis = ImmutableSet.of(X86_64, X86, ARM64_V8A, ARMEABI_V7A);
ApexImages apexConfig = apexImages(targetedImageWithBuildInfoAndAlternatives("apex/x86_64.img", "apex/x86_64.build_info.pb", X86_64, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/x86.img", "apex/x86.build_info.pb", X86, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/arm64-v8a.img", "apex/arm64-v8a.build_info.pb", ARM64_V8A, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/armeabi-v7a.img", "apex/armeabi-v7a.build_info.pb", ARMEABI_V7A, targetedAbis));
byte[] apexManifest = "{\"name\": \"com.test.app\"}".getBytes(UTF_8);
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("apex/x86_64.img"), "x86_64".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86_64.build_info.pb"), "x86_64.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.img"), "x86".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.build_info.pb"), "x86.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.img"), "arm64-v8a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.build_info.pb"), "arm64-v8a.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.img"), "armeabi-v7a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.build_info.pb"), "armeabi-v7a.build_info".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).addFileWithContent(ZipPath.create("root/apex_manifest.json"), apexManifest).writeTo(tmpDir.resolve("base.zip"));
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/apex/x86_64.img").withContent("x86_64".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86_64.build_info.pb").withContent("x86_64.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86.img").withContent("x86".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/x86.build_info.pb").withContent("x86.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.img").withContent("arm64-v8a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/arm64-v8a.build_info.pb").withContent("arm64-v8a.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.img").withContent("armeabi-v7a".getBytes(UTF_8));
assertThat(bundle).hasFile("base/apex/armeabi-v7a.build_info.pb").withContent("armeabi-v7a.build_info".getBytes(UTF_8));
assertThat(bundle).hasFile("base/root/apex_manifest.json").withContent(apexManifest);
assertThat(bundle).hasFile("base/apex.pb").withContent(apexConfig.toByteArray());
}
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class BuildBundleCommandTest method validModule.
@Test
public void validModule() throws Exception {
XmlNode manifest = androidManifest(PKG_NAME, withHasCode(true));
ResourceTable resourceTable = new ResourceTableBuilder().addPackage(PKG_NAME).addDrawableResource("icon", "res/drawable/icon.png").build();
Path module = new ZipBuilder().addFileWithContent(ZipPath.create("assets/anything.dat"), "any".getBytes(UTF_8)).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"));
BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
assertThat(bundle).hasFile("base/assets/anything.dat").withContent("any".getBytes(UTF_8));
assertThat(bundle).hasFile("base/dex/classes.dex").withContent("dex".getBytes(UTF_8));
assertThat(bundle).hasFile("base/lib/x86/libX.so").withContent("native".getBytes(UTF_8));
assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
assertThat(bundle).hasFile("base/res/drawable/icon.png").withContent("image".getBytes(UTF_8));
assertThat(bundle).hasFile("base/root/anything2.dat").withContent("any2".getBytes(UTF_8));
assertThat(bundle).hasFile("base/resources.pb").withContent(resourceTable.toByteArray());
}
}
use of com.android.aapt.Resources.XmlNode in project bundletool by google.
the class DumpManagerTest method dumpManifest_moduleNotBase.
@Test
public void dumpManifest_moduleNotBase() throws Exception {
XmlNode manifestBase = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").addAttribute(XmlAttribute.newBuilder().setName("package").setValue("base"))).build();
XmlNode manifestModule = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").addAttribute(XmlAttribute.newBuilder().setName("package").setValue("module"))).build();
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(manifestBase)).addModule("module", module -> module.setManifest(manifestModule)).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setModuleName("module").setOutputStream(new PrintStream(outputStream)).build().execute();
assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo(String.format("<manifest package=\"module\" split=\"module\"/>%n"));
}
Aggregations