Search in sources :

Example 76 with InvalidBundleException

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

the class ResourceTableValidatorTest method duplicateResourceId_differentModule_throws.

@Test
public void duplicateResourceId_differentModule_throws() throws Exception {
    BundleModule firstModule = new BundleModuleBuilder("base").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x0002, "logo"))))).setManifest(androidManifest("com.test.app")).build();
    BundleModule secondModule = new BundleModuleBuilder("secondModule").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x0002, "logo"))))).setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ResourceTableValidator().checkResourceIds(ImmutableList.of(firstModule, secondModule)));
    assertThat(exception).hasMessageThat().contains("Duplicate resource");
}
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 77 with InvalidBundleException

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

the class ModuleDependencyValidatorTest method validateAllModules_instantModuleToOnDemandModulesDependency_throws.

@Test
public void validateAllModules_instantModuleToOnDemandModulesDependency_throws() throws Exception {
    ImmutableList<BundleModule> allModules = ImmutableList.of(module("base", androidManifest(PKG_NAME, withInstant(true))), module("feature1", androidManifest(PKG_NAME, withOnDemandAttribute(true), withInstant(false))), module("feature2", androidManifest(PKG_NAME, withUsesSplit("feature1"), withInstant(true))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ModuleDependencyValidator().validateAllModules(allModules));
    assertThat(exception).hasMessageThat().contains("Instant module 'feature2' cannot depend on a module 'feature1' that is not instant.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 78 with InvalidBundleException

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

the class ModuleDependencyValidatorTest method validateAllModules_conditionalModule_dependsOnConditional_throws.

@Test
public void validateAllModules_conditionalModule_dependsOnConditional_throws() throws Exception {
    ImmutableList<BundleModule> allModules = ImmutableList.of(module("base", androidManifest(PKG_NAME)), module("conditional", androidManifest(PKG_NAME, withFeatureCondition("android.feature"), withUsesSplit("conditional2"))), module("conditional2", androidManifest(PKG_NAME, withFeatureCondition("android.feature2"))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ModuleDependencyValidator().validateAllModules(allModules));
    assertThat(exception).hasMessageThat().contains("Conditional module 'conditional' cannot depend on a module 'conditional2' that is " + "not install-time.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 79 with InvalidBundleException

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

the class ModuleDependencyValidatorTest method validateAllModules_cycle_throws.

@Test
public void validateAllModules_cycle_throws() throws Exception {
    ImmutableList<BundleModule> allModules = ImmutableList.of(module("base", androidManifest(PKG_NAME)), module("module1", androidManifest(PKG_NAME, withUsesSplit("module2"))), module("module2", androidManifest(PKG_NAME, withUsesSplit("module3"))), module("module3", androidManifest(PKG_NAME, withUsesSplit("module1"))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ModuleDependencyValidator().validateAllModules(allModules));
    assertThat(exception).hasMessageThat().contains("Found cyclic dependency between modules");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 80 with InvalidBundleException

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

the class ModuleDependencyValidatorTest method validateAllModules_assetModuleHasDependee_throws.

@Test
public void validateAllModules_assetModuleHasDependee_throws() throws Exception {
    ImmutableList<BundleModule> allModules = ImmutableList.of(module("base", androidManifest(PKG_NAME)), module("asset", androidManifestForAssetModule(PKG_NAME, withOnDemandDelivery())), module("feature", androidManifest(PKG_NAME, withOnDemandDelivery(), withUsesSplit("asset"))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ModuleDependencyValidator().validateAllModules(allModules));
    assertThat(exception).hasMessageThat().contains("Module 'feature' cannot depend on module 'asset' because one of them is an asset" + " pack.");
}
Also used : 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