Search in sources :

Example 11 with AppBundleSerializer

use of com.android.tools.build.bundletool.io.AppBundleSerializer 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 12 with AppBundleSerializer

use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.

the class BuildApksValidationTest method createAppBundle.

private static void createAppBundle(Path path) throws IOException {
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app")).build()).build();
    new AppBundleSerializer().writeToDisk(appBundle, path);
}
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) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer)

Example 13 with AppBundleSerializer

use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.

the class DumpManagerTest method dumpManifest_withXPath_noNamespaceDeclaration.

@Test
public void dumpManifest_withXPath_noNamespaceDeclaration() throws Exception {
    XmlNode manifestWithoutNamespaceDeclaration = androidManifest("com.app", withDebuggableAttribute(true), manifestElement -> manifestElement.getProto().clearNamespaceDeclaration());
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(manifestWithoutNamespaceDeclaration)).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setXPathExpression("/manifest/application/@android:debuggable").setOutputStream(new PrintStream(outputStream)).build().execute();
    assertThat(new String(outputStream.toByteArray(), UTF_8).trim()).isEqualTo("true");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ManifestProtoUtils.withMetadataValue(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMetadataValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) RunWith(org.junit.runner.RunWith) XmlAttribute(com.android.aapt.Resources.XmlAttribute) DumpTarget(com.android.tools.build.bundletool.commands.DumpCommand.DumpTarget) Bundletool(com.android.bundle.Config.Bundletool) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) Path(java.nio.file.Path) ResourceTable(com.android.aapt.Resources.ResourceTable) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) PrintStream(java.io.PrintStream) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) Rule(org.junit.Rule) XmlNode(com.android.aapt.Resources.XmlNode) BundleConfig(com.android.bundle.Config.BundleConfig) ManifestProtoUtils.withDebuggableAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withDebuggableAttribute) XmlElement(com.android.aapt.Resources.XmlElement) Compression(com.android.bundle.Config.Compression) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) PrintStream(java.io.PrintStream) XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 14 with AppBundleSerializer

use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.

the class DumpManagerTest method dumpManifest_withXPath_nodeResult.

@Test
public void dumpManifest_withXPath_nodeResult() throws Exception {
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app", withMetadataValue("key1", "value1"), withMetadataValue("key2", "value2")))).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DumpCommand dumpCommand = DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setXPathExpression("/manifest/application/meta-data").setOutputStream(new PrintStream(outputStream)).build();
    assertThrows(UnsupportedOperationException.class, () -> dumpCommand.execute());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ManifestProtoUtils.withMetadataValue(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMetadataValue) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) RunWith(org.junit.runner.RunWith) XmlAttribute(com.android.aapt.Resources.XmlAttribute) DumpTarget(com.android.tools.build.bundletool.commands.DumpCommand.DumpTarget) Bundletool(com.android.bundle.Config.Bundletool) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) Path(java.nio.file.Path) ResourceTable(com.android.aapt.Resources.ResourceTable) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Before(org.junit.Before) PrintStream(java.io.PrintStream) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) Rule(org.junit.Rule) XmlNode(com.android.aapt.Resources.XmlNode) BundleConfig(com.android.bundle.Config.BundleConfig) ManifestProtoUtils.withDebuggableAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withDebuggableAttribute) XmlElement(com.android.aapt.Resources.XmlElement) Compression(com.android.bundle.Config.Compression) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) PrintStream(java.io.PrintStream) AppBundle(com.android.tools.build.bundletool.model.AppBundle) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 15 with AppBundleSerializer

use of com.android.tools.build.bundletool.io.AppBundleSerializer in project bundletool by google.

the class DumpManagerTest method createBundle.

private static void createBundle(Path bundlePath, ResourceTable resourceTable, BundleConfig bundleConfig) throws IOException {
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app")).setResourceTable(resourceTable)).setBundleConfig(bundleConfig).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
}
Also used : AppBundle(com.android.tools.build.bundletool.model.AppBundle) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer)

Aggregations

AppBundleSerializer (com.android.tools.build.bundletool.io.AppBundleSerializer)32 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)27 Test (org.junit.Test)27 AppBundle (com.android.tools.build.bundletool.model.AppBundle)25 Path (java.nio.file.Path)25 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)24 Truth.assertThat (com.google.common.truth.Truth.assertThat)24 Before (org.junit.Before)24 Rule (org.junit.Rule)24 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)24 TemporaryFolder (org.junit.rules.TemporaryFolder)24 RunWith (org.junit.runner.RunWith)24 JUnit4 (org.junit.runners.JUnit4)23 IOException (java.io.IOException)18 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 PrintStream (java.io.PrintStream)17 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)17 ImmutableList (com.google.common.collect.ImmutableList)15 XmlNode (com.android.aapt.Resources.XmlNode)7 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)7