Search in sources :

Example 86 with InvalidBundleException

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

the class ModuleNamesValidatorTest method moreThanOneModuleWithoutSplitId.

@Test
public void moreThanOneModuleWithoutSplitId() {
    BundleModule base1 = buildBundleModule("base").setAndroidManifestProto(androidManifest("com.app")).build();
    BundleModule base2 = buildBundleModule("base").setAndroidManifestProto(androidManifest("com.app")).build();
    InvalidBundleException expected = assertThrows(InvalidBundleException.class, () -> new ModuleNamesValidator().validateAllModules(ImmutableList.of(base1, base2)));
    assertThat(expected).hasMessageThat().contains("More than one module was found without the 'split' attribute set in the " + "AndroidManifest.xml.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 87 with InvalidBundleException

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

the class ModuleNamesValidatorTest method splitIdDoesNotMatchModuleName.

@Test
public void splitIdDoesNotMatchModuleName() {
    BundleModule base = buildBundleModule("base").setAndroidManifestProto(androidManifest("com.app")).build();
    BundleModule feature = buildBundleModule("module").setAndroidManifestProto(androidManifest("com.app", withSplitId("feature"))).build();
    InvalidBundleException expected = assertThrows(InvalidBundleException.class, () -> new ModuleNamesValidator().validateAllModules(ImmutableList.of(base, feature)));
    assertThat(expected).hasMessageThat().contains("The 'split' attribute in the AndroidManifest.xml of modules must be the name of the " + "module, but has the value 'feature' in module 'module'");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 88 with InvalidBundleException

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

the class ModuleTitleValidatorTest method validateAllModules_onDemandModuleTitleMissingInResourceTable_throws.

@Test
public void validateAllModules_onDemandModuleTitleMissingInResourceTable_throws() throws Exception {
    ImmutableList<BundleModule> allModules = ImmutableList.of(module("base", androidManifest(PKG_NAME)), module("demand", androidManifest(PKG_NAME, withOnDemandAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ModuleTitleValidator().validateAllModules(allModules));
    assertThat(exception).hasMessageThat().contains("is missing in the base resource table");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 89 with InvalidBundleException

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

the class AssetModuleFilesValidatorTest method moduleWithResourceTable_throws.

@Test
public void moduleWithResourceTable_throws() throws Exception {
    BundleModule module = new BundleModuleBuilder(MODULE_NAME).setManifest(androidManifestForAssetModule(PKG_NAME)).setResourceTable(ResourceTable.getDefaultInstance()).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new AssetModuleFilesValidator().validateModule(module));
    assertThat(exception).hasMessageThat().matches("Unexpected resource table found in asset pack 'assetmodule'.");
}
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 90 with InvalidBundleException

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

the class AssetModuleFilesValidatorTest method moduleWithNativeConfig_throws.

@Test
public void moduleWithNativeConfig_throws() throws Exception {
    NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(DXT1)));
    BundleModule module = new BundleModuleBuilder(MODULE_NAME).setManifest(androidManifestForAssetModule(PKG_NAME)).setNativeConfig(config).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new AssetModuleFilesValidator().validateModule(module));
    assertThat(exception).hasMessageThat().matches("Native libraries config not allowed in asset packs, but found in 'assetmodule'.");
}
Also used : NativeLibraries(com.android.bundle.Files.NativeLibraries) 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)

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