use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class WearApkLocatorTest method moreThanOneXmlDescriptionFile_throws.
@Test
public void moreThanOneXmlDescriptionFile_throws() {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage(PACKAGE_NAME).addFileResourceForMultipleConfigs(XML_TYPE, WEAR_DESC_XML_RES_NAME, ImmutableMap.of(Configuration.newBuilder().setDensity(240).build(), "res/xml-hdpi/wearable_app_desc.xml", Configuration.getDefaultInstance(), WEAR_DESC_XML_RES_PATH)).addFileResource(RAW_TYPE, WEAR_APK_RES_NAME, wearableApkPath.toString()).build();
AndroidManifest androidManifest = buildAndroidManifestForWearApk(resourceTable);
ImmutableList<ModuleEntry> entries = buildEntriesForEmbeddedWearApk(wearableApkPath);
ModuleSplit moduleSplit = createModuleSplit(androidManifest, resourceTable, entries);
InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> WearApkLocator.findEmbeddedWearApkPaths(moduleSplit));
assertThat(exception).hasMessageThat().isEqualTo("More than one embedded Wear APK is not supported.");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class BuildBundleCommandTest method buildUncompressedBundle.
@Test
public void buildUncompressedBundle() throws Exception {
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().addPackage(PKG_NAME).addDrawableResource("hello", "res/raw/hello.png").build()).writeTo(tmpDir.resolve("base.zip"));
Path mainDexList = Files.createFile(tmp.getRoot().toPath().resolve("mainDexList.txt"));
BuildBundleCommand.builder().setModulesPaths(ImmutableList.of(module)).setOutputPath(bundlePath).setMainDexListFile(mainDexList).setUncompressedBundle(true).build().execute();
try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
Enumeration<? extends ZipEntry> entries = bundle.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
assertWithMessage("Entry %s is not uncompressed.", entry.getName()).that(entry.getMethod()).isEqualTo(ZipEntry.STORED);
}
}
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder 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.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class BuildBundleCommandTest method runsResourceTableValidator_resourceTableReferencingNonExistingFile_throws.
@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();
InvalidBundleException exception = assertThrows(InvalidBundleException.class, command::execute);
assertThat(exception).hasMessageThat().contains("contains references to non-existing files");
}
use of com.android.tools.build.bundletool.testing.ResourceTableBuilder in project bundletool by google.
the class DumpManagerTest method dumpResources_allTable.
@Test
public void dumpResources_allTable() throws Exception {
createBundle(bundlePath, new ResourceTableBuilder().addPackage("com.app").addStringResourceForMultipleLocales("title", ImmutableSortedMap.of("en", "Title", "pt", "TÃtulo")).addDrawableResourceForMultipleDensities("icon", ImmutableSortedMap.of(160, "res/drawable/icon.png", 240, "res/drawable-hdpi/icon.png")).build());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.RESOURCES).setOutputStream(new PrintStream(outputStream)).build().execute();
String output = new String(outputStream.toByteArray(), UTF_8);
assertThat(output).isEqualTo(String.format("Package 'com.app':%n" + "0x7f010000 - string/title%n" + "\tlocale: \"en\"%n" + "\tlocale: \"pt\"%n" + "0x7f020000 - drawable/icon%n" + "\tdensity: 160%n" + "\tdensity: 240%n%n"));
}
Aggregations