Search in sources :

Example 16 with InvalidBundleException

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

the class BundleConfigValidatorTest method masterResources_undefinedResourceId_throws.

@Test
public void masterResources_undefinedResourceId_throws() throws Exception {
    ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addStringResource("label", "Hello World").build();
    int nonExistentResourceId = ResourcesUtils.entries(resourceTable).findFirst().get().getResourceId().getFullResourceId() + 1;
    AppBundle appBundle = createAppBundleBuilder(BundleConfigBuilder.create().addResourcePinnedToMasterSplit(nonExistentResourceId)).addModule("feature", module -> module.setResourceTable(resourceTable).setManifest(androidManifest("com.test.app"))).build();
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleConfigValidator().validateBundle(appBundle));
    assertThat(e).hasMessageThat().contains("The Master Resources list contains resource IDs not defined in any module. " + "For example: 0x7f010001");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) SuffixStripping(com.android.bundle.Config.SuffixStripping) BundleToolVersion(com.android.tools.build.bundletool.model.version.BundleToolVersion) Value(com.android.bundle.Config.SplitDimension.Value) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) RunWith(org.junit.runner.RunWith) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) BundleConfig(com.android.bundle.Config.BundleConfig) ResourcesUtils(com.android.tools.build.bundletool.model.utils.ResourcesUtils) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) SplitDimension(com.android.bundle.Config.SplitDimension) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ResourceTable(com.android.aapt.Resources.ResourceTable) AppBundle(com.android.tools.build.bundletool.model.AppBundle) 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 17 with InvalidBundleException

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

the class BundleConfigValidatorTest method version_invalid_throws.

@Test
public void version_invalid_throws() throws Exception {
    AppBundle appBundle = createAppBundle(BundleConfigBuilder.create().setVersion("blah"));
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleConfigValidator().validateBundle(appBundle));
    assertThat(e).hasMessageThat().contains("Invalid version");
}
Also used : AppBundle(com.android.tools.build.bundletool.model.AppBundle) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 18 with InvalidBundleException

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

the class BundleFilesValidatorTest method validateApexFile_repeatingAbis_throws.

@Test
public void validateApexFile_repeatingAbis_throws() throws Exception {
    ZipPath repeatingAbisFile = ZipPath.create("apex/x86.x86_64.x86.img");
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(repeatingAbisFile));
    assertThat(e).hasMessageThat().contains("Repeating architectures in APEX system image file");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 19 with InvalidBundleException

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

the class BundleFilesValidatorTest method validateLibFile_nonSoExtension_throws.

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

Example 20 with InvalidBundleException

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

the class BundleFilesValidatorTest method validateApexFile_nonImgExtension_throws.

@Test
public void validateApexFile_nonImgExtension_throws() throws Exception {
    ZipPath nonImgFile = ZipPath.create("apex/x86.dat");
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new BundleFilesValidator().validateModuleFile(nonImgFile));
    assertThat(e).hasMessageThat().contains("Files under apex/ must have .img extension");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ZipPath(com.android.tools.build.bundletool.model.ZipPath) 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