Search in sources :

Example 41 with ResourceTableBuilder

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.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 42 with ResourceTableBuilder

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);
        }
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Test(org.junit.Test)

Example 43 with ResourceTableBuilder

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());
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) XmlNode(com.android.aapt.Resources.XmlNode) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 44 with ResourceTableBuilder

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");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 45 with ResourceTableBuilder

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"));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Test(org.junit.Test)

Aggregations

ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)77 Test (org.junit.Test)77 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)44 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)44 BundleModule (com.android.tools.build.bundletool.model.BundleModule)40 ResourceTable (com.android.aapt.Resources.ResourceTable)35 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)25 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)24 Truth.assertThat (com.google.common.truth.Truth.assertThat)24 RunWith (org.junit.runner.RunWith)24 ImmutableMap (com.google.common.collect.ImmutableMap)21 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)21 ImmutableList (com.google.common.collect.ImmutableList)20 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)20 MoreCollectors.onlyElement (com.google.common.collect.MoreCollectors.onlyElement)20 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)18 Theories (org.junit.experimental.theories.Theories)18 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)16 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)16 Collection (java.util.Collection)16