Search in sources :

Example 56 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class BundleFilesValidatorTest method validateOtherFile_inUnknownDirectory_throws.

@Test
public void validateOtherFile_inUnknownDirectory_throws() throws Exception {
    ZipPath otherFile = ZipPath.create("unrecognized/path.txt");
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(otherFile));
    assertThat(e).hasMessageThat().contains("Module files can be only in pre-defined directories");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 57 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class BundleFilesValidatorTest method validateDexFile_nonDexExtension_throws.

@Test
public void validateDexFile_nonDexExtension_throws() throws Exception {
    ZipPath nonDexFile = ZipPath.create("dex/classes.dat");
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(nonDexFile));
    assertThat(e).hasMessageThat().contains("Files under dex/ must have .dex extension, found 'dex/classes.dat'.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 58 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class BundleZipValidatorTest method validateBundleZipEntry_directory_throws.

@Test
public void validateBundleZipEntry_directory_throws() throws Exception {
    Path bundlePath = new ZipBuilder().addDirectory(ZipPath.create("directory")).writeTo(tempFolder.resolve("bundle.aab"));
    try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
        ArrayList<? extends ZipEntry> entries = Collections.list(bundleZip.entries());
        // Sanity check.
        assertThat(entries).hasSize(1);
        InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new BundleZipValidator().validateBundleZipEntry(bundleZip, entries.get(0)));
        assertThat(exception).hasMessageThat().contains("zip file contains directory zip entry");
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) Path(java.nio.file.Path) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 59 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class DeviceTierParityValidatorTest method tierNumbersNotContiguous_throws.

@Test
public void tierNumbersNotContiguous_throws() {
    BundleModule moduleA = new BundleModuleBuilder("a").addFile("assets/img1#tier_0/image.jpg").addFile("assets/img1#tier_2/image.jpg").setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new DeviceTierParityValidator().validateAllModules(ImmutableList.of(moduleA)));
    assertThat(exception).hasMessageThat().contains("All modules with device tier targeting must support the same contiguous" + " range of tier values starting from 0, but module 'a' supports [0, 2].");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 60 with InvalidBundleException

use of com.android.tools.build.bundletool.model.exceptions.InvalidBundleException in project bundletool by google.

the class TextureCompressionFormatParityValidatorTest method tcfsWithNoFallbackAndNoConfig_throws.

@Test
public void tcfsWithNoFallbackAndNoConfig_throws() throws Exception {
    BundleModule moduleA = new BundleModuleBuilder("a").addFile("assets/textures#tcf_astc/level1.assets").addFile("assets/textures#tcf_etc2/level1.assets").setManifest(androidManifest("com.test.app")).build();
    BundleModule moduleB = new BundleModuleBuilder("b").addFile("assets/other_textures#tcf_astc/astc_file.assets").addFile("assets/other_textures#tcf_etc2/etc2_file.assets").setManifest(androidManifest("com.test.app")).build();
    AppBundle appBundle = new AppBundleBuilder().addModule(moduleA).addModule(moduleB).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
    false).build()).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new TextureCompressionFormatParityValidator().validateBundle(appBundle));
    assertThat(exception).hasMessageThat().contains("When a standalone or universal APK is built, the fallback texture folders (folders" + " without #tcf suffixes) will be used, but module 'a' has no such folders." + " Instead, it has folder(s) targeted for formats [ASTC, ETC2] (without fallback" + " directories). Either add missing folders or change the configuration for the" + " TEXTURE_COMPRESSION_FORMAT optimization to specify a default suffix" + " corresponding to the format to use in the standalone and universal APKs.");
}
Also used : AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)188 Test (org.junit.Test)188 BundleModule (com.android.tools.build.bundletool.model.BundleModule)106 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)69 ZipPath (com.android.tools.build.bundletool.model.ZipPath)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)17 XmlNode (com.android.aapt.Resources.XmlNode)14 Path (java.nio.file.Path)14 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)12 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)10 ResourceTable (com.android.aapt.Resources.ResourceTable)9 ZipFile (java.util.zip.ZipFile)9 ZipBuilder (com.android.tools.build.bundletool.io.ZipBuilder)8 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)8 ApexImages (com.android.bundle.Files.ApexImages)6 NativeLibraries (com.android.bundle.Files.NativeLibraries)6 BundleConfigBuilder (com.android.tools.build.bundletool.testing.BundleConfigBuilder)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)6 IOException (java.io.IOException)6 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)6