Search in sources :

Example 41 with InvalidBundleException

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

the class ManifestDeliveryElementTest method moduleConditions_multipleDeviceGroupsCondition_throws.

@Test
public void moduleConditions_multipleDeviceGroupsCondition_throws() {
    Optional<ManifestDeliveryElement> element = ManifestDeliveryElement.fromManifestRootNode(androidManifest("com.test.app", withDeviceGroupsCondition(ImmutableList.of("group1", "group2")), withDeviceGroupsCondition(ImmutableList.of("group3"))), /* isFastFollowAllowed= */
    false);
    assertThat(element).isPresent();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> element.get().getModuleConditions());
    assertThat(exception).hasMessageThat().contains("Multiple '<dist:device-groups>' conditions are not supported.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 42 with InvalidBundleException

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

the class ManifestDeliveryElementTest method getModuleConditions_multipleUserCountriesConditions_throws.

@Test
public void getModuleConditions_multipleUserCountriesConditions_throws() {
    Optional<ManifestDeliveryElement> element = ManifestDeliveryElement.fromManifestRootNode(androidManifest("com.test.app", withUserCountriesCondition(ImmutableList.of("en", "us")), withUserCountriesCondition(ImmutableList.of("sg"), /* exclude= */
    true)), /* isFastFollowAllowed= */
    false);
    assertThat(element).isPresent();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> element.get().getModuleConditions());
    assertThat(exception).hasMessageThat().contains("Multiple '<dist:user-countries>' conditions are not supported.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 43 with InvalidBundleException

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

the class ModuleConditionsTest method multipleDeviceFeatureConditions_sameFeatureName_throws.

@Test
public void multipleDeviceFeatureConditions_sameFeatureName_throws() {
    ModuleConditions.Builder builder = ModuleConditions.builder();
    builder.addDeviceFeatureCondition(DeviceFeatureCondition.create("com.android.feature", /* version= */
    Optional.of(1)));
    builder.addDeviceFeatureCondition(DeviceFeatureCondition.create("com.android.feature", /* version= */
    Optional.of(2)));
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, builder::build);
    assertThat(exception).hasMessageThat().contains("The device feature condition on 'com.android.feature' " + "is present more than once.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) Test(org.junit.Test)

Example 44 with InvalidBundleException

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

the class BuildApksValidationTest method splits_textureFallbackNotPresentInAssetPacks.

@Test
public void splits_textureFallbackNotPresentInAssetPacks() throws Exception {
    AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature_tcf_assets", builder -> builder.addFile("assets/textures#tcf_atc/atc_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures#tcf_atc", assetsDirectoryTargeting(textureCompressionTargeting(ATC))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForFeature("com.test.app", withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
    false).build()).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
    // Splitting by texture compression format is activated, but the textures in
    // one module don't include a fallback folder, used for standalone and universal
    // APKs, so we'll consider the bundle invalid:
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("the fallback texture folders (folders without #tcf suffixes) will be used, but module" + " 'feature_tcf_assets' has no such folders.");
}
Also used : ManifestProtoUtils.withMaxSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMaxSdkVersion) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) TEST_LABEL_RESOURCE_ID(com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID) Value(com.android.bundle.Config.SplitDimension.Value) TargetingUtils.alternativeTextureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeTextureCompressionTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) TargetingUtils.textureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionTargeting) ATC(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ATC) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) RunWith(org.junit.runner.RunWith) ImmutableList(com.google.common.collect.ImmutableList) TargetingUtils.targetedAssetsDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedAssetsDirectory) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ResourcesTableFactory.resourceTableWithTestLabel(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTableWithTestLabel) Path(java.nio.file.Path) Before(org.junit.Before) ManifestProtoUtils.withInstant(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstant) ManifestProtoUtils.withTitle(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withTitle) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) ETC1_RGB8(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ETC1_RGB8) TargetingUtils.assets(com.android.tools.build.bundletool.testing.TargetingUtils.assets) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) Rule(org.junit.Rule) SubValidator(com.android.tools.build.bundletool.validation.SubValidator) ManifestProtoUtils.androidManifestForFeature(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForFeature) TargetingUtils.assetsDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) AppBundle(com.android.tools.build.bundletool.model.AppBundle) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) Test(org.junit.Test)

Example 45 with InvalidBundleException

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

the class BuildBundleCommandTest method runsModuleDependencyValidator_cycle_throws.

@Test
public void runsModuleDependencyValidator_cycle_throws() throws Exception {
    Path baseModulePath = new ZipBuilder().addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME)).writeTo(tmpDir.resolve("base.zip"));
    Path module1Path = new ZipBuilder().addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME, withSplitId("module1"), withUsesSplit("module2"), withOnDemandAttribute(false), withFusingAttribute(true))).writeTo(tmpDir.resolve("module1.zip"));
    Path module2Path = new ZipBuilder().addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME, withSplitId("module2"), withUsesSplit("module3"), withOnDemandAttribute(false), withFusingAttribute(true))).writeTo(tmpDir.resolve("module2.zip"));
    Path module3Path = new ZipBuilder().addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME, withSplitId("module3"), withUsesSplit("module1"), withOnDemandAttribute(false), withFusingAttribute(true))).writeTo(tmpDir.resolve("module3.zip"));
    BuildBundleCommand command = BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(baseModulePath, module1Path, module2Path, module3Path)).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("Found cyclic dependency between modules");
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) 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