Search in sources :

Example 46 with InvalidBundleException

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

the class BuildBundleCommandTest method runsBundleFilesValidator_rogueFileInModuleRoot_throws.

// Tests bellow validate that specific validators are run for the input modules. For the lack
// of better options, for each validator there is a single test that is most representative of
// the validator.
@Test
public void runsBundleFilesValidator_rogueFileInModuleRoot_throws() throws Exception {
    Path module = new ZipBuilder().addFileWithContent(ZipPath.create("rogue.txt"), "".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), androidManifest(PKG_NAME)).writeTo(tmpDir.resolve("base.zip"));
    BuildBundleCommand command = BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, command::execute);
    assertThat(exception).hasMessageThat().contains("Module files can be only in pre-defined directories");
}
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)

Example 47 with InvalidBundleException

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

the class WearApkLocatorTest method xmlDescriptionFileNotParseable_throws.

@Test
public void xmlDescriptionFileNotParseable_throws() {
    ResourceTable resourceTable = buildResourceTableForEmbeddedWearApk(wearableApkPath);
    AndroidManifest androidManifest = buildAndroidManifestForWearApk(resourceTable);
    ImmutableList<ModuleEntry> entries = ImmutableList.of(createModuleEntryForFile(WEAR_DESC_XML_RES_PATH, "RandomText".getBytes(UTF_8)));
    ModuleSplit moduleSplit = createModuleSplit(androidManifest, resourceTable, entries);
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> WearApkLocator.findEmbeddedWearApkPaths(moduleSplit));
    assertThat(exception).hasMessageThat().isEqualTo("The wear APK description file 'res/xml/wearable_app_desc.xml' could not be parsed.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 48 with InvalidBundleException

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

the class WearApkLocatorTest method embeddedWearApkNotAtDesignedLocation_throws.

@Test
public void embeddedWearApkNotAtDesignedLocation_throws() {
    ResourceTable resourceTable = buildResourceTableForEmbeddedWearApk(wearableApkPath);
    AndroidManifest androidManifest = buildAndroidManifestForWearApk(resourceTable);
    ImmutableList<ModuleEntry> entries = ImmutableList.of(createModuleEntryForFile(WEAR_DESC_XML_RES_PATH, createEmbeddedWearableAppXmlDescription(WEAR_APK_RES_NAME).toByteArray()));
    ModuleSplit moduleSplit = createModuleSplit(androidManifest, resourceTable, entries);
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> WearApkLocator.findEmbeddedWearApkPaths(moduleSplit));
    assertThat(exception).hasMessageThat().isEqualTo("Wear APK expected at location 'res/raw/wear.apk' but was not found.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 49 with InvalidBundleException

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

the class WearApkLocatorTest method resourceReferencedInMetadataDoesNotExist_throws.

@Test
public void resourceReferencedInMetadataDoesNotExist_throws() {
    ResourceTable resourceTable = new ResourceTableBuilder().addPackage(PACKAGE_NAME).build();
    AndroidManifest androidManifest = AndroidManifest.create(androidManifest(PACKAGE_NAME, withMetadataResource(WEAR_APK_1_0_METADATA_KEY, 0x7F000000)));
    ImmutableList<ModuleEntry> entries = buildEntriesForEmbeddedWearApk(wearableApkPath);
    ModuleSplit moduleSplit = createModuleSplit(androidManifest, resourceTable, entries);
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> WearApkLocator.findEmbeddedWearApkPaths(moduleSplit));
    assertThat(exception).hasMessageThat().isEqualTo("Resource 0x7f000000 is referenced in the manifest in the " + "'com.google.android.wearable.beta.app' metadata, but was not found in the " + "resource table.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 50 with InvalidBundleException

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

the class WearApkLocatorTest method xmlDescriptionResourceNotPointingAtFile_throws.

@Test
public void xmlDescriptionResourceNotPointingAtFile_throws() {
    ResourceTable resourceTable = new ResourceTableBuilder().addPackage(PACKAGE_NAME).addResource(XML_TYPE, WEAR_DESC_XML_RES_NAME, ConfigValue.newBuilder().setValue(newStringValue(WEAR_DESC_XML_RES_PATH)).build()).addFileResource(RAW_TYPE, WEAR_APK_RES_NAME, WEAR_APK_RES_PATH).build();
    AndroidManifest androidManifest = buildAndroidManifestForWearApk(resourceTable);
    ImmutableList<ModuleEntry> entries = buildEntriesForEmbeddedWearApk(wearableApkPath);
    ModuleSplit moduleSplit = createModuleSplit(androidManifest, resourceTable, entries);
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> WearApkLocator.findEmbeddedWearApkPaths(moduleSplit));
    assertThat(exception).hasMessageThat().isEqualTo("No XML description file path found for Wear APK.");
}
Also used : InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) 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