Search in sources :

Example 66 with InvalidBundleException

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

the class DexFilesValidatorTest method noDexFiles_hasCodeNotSet_throws.

@Test
public void noDexFiles_hasCodeNotSet_throws() throws Exception {
    BundleModule module = new BundleModuleBuilder("base").addFile("manifest/AndroidManifest.xml", androidManifest("com.test.app", clearHasCode()).toByteArray()).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new DexFilesValidator().validateModule(module));
    assertThat(exception).hasMessageThat().contains("Module 'base' has no dex files but the attribute 'hasCode' is not set to false " + "in the AndroidManifest.xml.");
}
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 67 with InvalidBundleException

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

the class DexFilesValidatorTest method singleDexFile_invalid_throws.

@Test
public void singleDexFile_invalid_throws() throws Exception {
    BundleModule module = new BundleModuleBuilder("base").addFile("dex/classes2.dex").setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new DexFilesValidator().validateModule(module));
    assertThat(exception).hasMessageThat().contains("expecting file 'classes.dex' but found 'classes2.dex'");
}
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 68 with InvalidBundleException

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

the class EntryClashValidatorTest method entryNameCollision_theSameFileBetweenBaseAndAssetModule_throws.

@Test
public void entryNameCollision_theSameFileBetweenBaseAndAssetModule_throws() throws Exception {
    String fileName = "assets/file.txt";
    byte[] fileContentA = { 'a' };
    BundleModule baseModule = new BundleModuleBuilder("base").addFile(fileName, fileContentA).setManifest(androidManifest("com.test.app")).build();
    BundleModule assetModule = new BundleModuleBuilder("assets1").addFile(fileName, fileContentA).setManifest(androidManifestForAssetModule("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new EntryClashValidator().validateAllModules(ImmutableList.of(baseModule, assetModule)));
    assertThat(exception).hasMessageThat().isEqualTo("Both modules 'base' and 'assets1' contain asset entry 'assets/file.txt'.");
}
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 69 with InvalidBundleException

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

the class MandatoryFilesPresenceValidatorTest method bundleZipFile_withoutBundleConfig_throws.

@Test
public void bundleZipFile_withoutBundleConfig_throws() throws Exception {
    Path bundlePath = new ZipBuilder().addFileWithContent(ZipPath.create("base/manifest/AndroidManifest.xml"), DUMMY_CONTENT).writeTo(tempFolder.resolve("bundle.aab"));
    try (ZipFile bundleZip = new ZipFile(bundlePath.toFile())) {
        InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new MandatoryFilesPresenceValidator(AppBundle.NON_MODULE_DIRECTORIES).validateBundleZipFile(bundleZip));
        assertThat(exception).hasMessageThat().contains("missing required file 'BundleConfig.pb'");
    }
}
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 70 with InvalidBundleException

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

the class ModuleDependencyValidatorTest method validateAllModules_onDemandModuleMinSdkSmallerThanOnDemandModule_fails.

@Test
public void validateAllModules_onDemandModuleMinSdkSmallerThanOnDemandModule_fails() throws Exception {
    ImmutableList<BundleModule> allModules = ImmutableList.of(module("base", androidManifest(PKG_NAME, withMinSdkVersion(20))), module("feature1", androidManifest(PKG_NAME, withOnDemandAttribute(true), withUsesSplit("feature2"), withMinSdkVersion(19))), module("feature2", androidManifest(PKG_NAME, withOnDemandAttribute(true), withMinSdkVersion(20))));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ModuleDependencyValidator().validateAllModules(allModules));
    assertThat(exception).hasMessageThat().contains("Conditional or on-demand module 'feature1' has a minSdkVersion(19), which is smaller " + "than the minSdkVersion(20) of its dependency 'feature2'.");
}
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