Search in sources :

Example 71 with InvalidBundleException

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

the class NativeTargetingValidatorTest method validateModule_pathOutsideLib_throws.

@Test
public void validateModule_pathOutsideLib_throws() throws Exception {
    NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("assets/lib/x86_64", nativeDirectoryTargeting(X86_64)));
    BundleModule module = new BundleModuleBuilder("testModule").setNativeConfig(config).addFile("lib/x86/libX.so").setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module));
    assertThat(e).hasMessageThat().contains("directory must be in format 'lib/<directory>'");
}
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)

Example 72 with InvalidBundleException

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

the class NativeTargetingValidatorTest method validateModule_directoriesUnderLibNotTargeted_throws.

@Test
public void validateModule_directoriesUnderLibNotTargeted_throws() throws Exception {
    NativeLibraries config = nativeLibraries(targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)));
    BundleModule module = new BundleModuleBuilder("testModule").addFile("lib/x86/libX.so").addFile("lib/x86_64/libX.so").addFile("lib/mips/libX.so").setNativeConfig(config).setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException e = assertThrows(InvalidBundleException.class, () -> new NativeTargetingValidator().validateModule(module));
    assertThat(e).hasMessageThat().contains("Following native directories are not targeted: [lib/x86, lib/x86_64]");
}
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)

Example 73 with InvalidBundleException

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

the class ResourceTableValidatorTest method validateModule_nonReferencedFile_throws.

@Test
public void validateModule_nonReferencedFile_throws() throws Exception {
    BundleModule module = new BundleModuleBuilder("module").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "res/drawable/icon.png").build()).setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ResourceTableValidator().validateModule(module));
    assertThat(exception).hasMessageThat().contains("contains references to non-existing files: [res/drawable/icon.png]");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 74 with InvalidBundleException

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

the class ResourceTableValidatorTest method validateModule_fileOutsideRes_throws.

@Test
public void validateModule_fileOutsideRes_throws() throws Exception {
    BundleModule module = new BundleModuleBuilder("module").addFile("assets/icon.png").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResource("icon", "assets/icon.png").build()).setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ResourceTableValidator().validateModule(module));
    assertThat(exception).hasMessageThat().contains("references file 'assets/icon.png' outside of the 'res/' directory");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 75 with InvalidBundleException

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

the class ResourceTableValidatorTest method validateModule_nonExistingFile_throws.

@Test
public void validateModule_nonExistingFile_throws() throws Exception {
    BundleModule module = new BundleModuleBuilder("module").setResourceTable(ResourceTable.getDefaultInstance()).addFile("res/drawable/icon.png").setManifest(androidManifest("com.test.app")).build();
    InvalidBundleException exception = assertThrows(InvalidBundleException.class, () -> new ResourceTableValidator().validateModule(module));
    assertThat(exception).hasMessageThat().contains("contains resource files that are not referenced from the resource table: " + "[res/drawable/icon.png]");
}
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)

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