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.");
}
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'");
}
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'.");
}
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'");
}
}
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'.");
}
Aggregations