Search in sources :

Example 76 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class BuildBundleCommandTest method assetsTargeting_generated.

@Test
public void assetsTargeting_generated() throws Exception {
    XmlNode manifest = androidManifest(PKG_NAME, withHasCode(true));
    Assets assetsConfig = Assets.newBuilder().addDirectory(TargetedAssetsDirectory.newBuilder().setPath("assets").setTargeting(AssetsDirectoryTargeting.getDefaultInstance())).addDirectory(TargetedAssetsDirectory.newBuilder().setPath("assets/texture#tcf_atc/device#tier_0").setTargeting(mergeAssetsTargeting(assetsDirectoryTargeting(textureCompressionTargeting(TextureCompressionFormatAlias.ATC)), assetsDirectoryTargeting(deviceTierTargeting(0))))).build();
    Path module = new ZipBuilder().addFileWithContent(ZipPath.create("assets/anything.dat"), "any".getBytes(UTF_8)).addFileWithContent(ZipPath.create("assets/texture#tcf_atc/device#tier_0/file.dat"), "any2".getBytes(UTF_8)).addFileWithContent(ZipPath.create("dex/classes.dex"), "dex".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).writeTo(tmpDir.resolve("base.zip"));
    BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
    try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
        assertThat(bundle).hasFile("base/assets/anything.dat").withContent("any".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/assets/texture#tcf_atc/device#tier_0/file.dat").withContent("any2".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/dex/classes.dex").withContent("dex".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
        assertThat(bundle).hasFile("base/assets.pb").withContent(assetsConfig.toByteArray());
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) XmlNode(com.android.aapt.Resources.XmlNode) ZipFile(java.util.zip.ZipFile) Assets(com.android.bundle.Files.Assets) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) Test(org.junit.Test)

Example 77 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class BuildBundleCommandTest method validApexModule.

@Test
public void validApexModule() throws Exception {
    XmlNode manifest = androidManifest(PKG_NAME, withHasCode(false));
    ImmutableSet<AbiAlias> targetedAbis = ImmutableSet.of(X86_64, X86, ARM64_V8A, ARMEABI_V7A);
    ApexImages apexConfig = apexImages(targetedImageWithAlternatives("apex/x86_64.img", X86_64, targetedAbis), targetedImageWithAlternatives("apex/x86.img", X86, targetedAbis), targetedImageWithAlternatives("apex/arm64-v8a.img", ARM64_V8A, targetedAbis), targetedImageWithAlternatives("apex/armeabi-v7a.img", ARMEABI_V7A, targetedAbis));
    byte[] apexManifest = "{\"name\": \"com.test.app\"}".getBytes(UTF_8);
    Path module = new ZipBuilder().addFileWithContent(ZipPath.create("apex/x86_64.img"), "x86_64".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.img"), "x86".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.img"), "arm64-v8a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.img"), "armeabi-v7a".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).addFileWithContent(ZipPath.create("root/apex_manifest.json"), apexManifest).writeTo(tmpDir.resolve("base.zip"));
    BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
    try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
        assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
        assertThat(bundle).hasFile("base/apex/x86_64.img").withContent("x86_64".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/x86.img").withContent("x86".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/arm64-v8a.img").withContent("arm64-v8a".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/armeabi-v7a.img").withContent("armeabi-v7a".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/root/apex_manifest.json").withContent(apexManifest);
        assertThat(bundle).hasFile("base/apex.pb").withContent(apexConfig.toByteArray());
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) XmlNode(com.android.aapt.Resources.XmlNode) ApexImages(com.android.bundle.Files.ApexImages) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Test(org.junit.Test)

Example 78 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class BuildBundleCommandTest method validApexModuleWithBuildInfo.

@Test
public void validApexModuleWithBuildInfo() throws Exception {
    XmlNode manifest = androidManifest(PKG_NAME, withHasCode(false));
    ImmutableSet<AbiAlias> targetedAbis = ImmutableSet.of(X86_64, X86, ARM64_V8A, ARMEABI_V7A);
    ApexImages apexConfig = apexImages(targetedImageWithBuildInfoAndAlternatives("apex/x86_64.img", "apex/x86_64.build_info.pb", X86_64, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/x86.img", "apex/x86.build_info.pb", X86, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/arm64-v8a.img", "apex/arm64-v8a.build_info.pb", ARM64_V8A, targetedAbis), targetedImageWithBuildInfoAndAlternatives("apex/armeabi-v7a.img", "apex/armeabi-v7a.build_info.pb", ARMEABI_V7A, targetedAbis));
    byte[] apexManifest = "{\"name\": \"com.test.app\"}".getBytes(UTF_8);
    Path module = new ZipBuilder().addFileWithContent(ZipPath.create("apex/x86_64.img"), "x86_64".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86_64.build_info.pb"), "x86_64.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.img"), "x86".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/x86.build_info.pb"), "x86.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.img"), "arm64-v8a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/arm64-v8a.build_info.pb"), "arm64-v8a.build_info".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.img"), "armeabi-v7a".getBytes(UTF_8)).addFileWithContent(ZipPath.create("apex/armeabi-v7a.build_info.pb"), "armeabi-v7a.build_info".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).addFileWithContent(ZipPath.create("root/apex_manifest.json"), apexManifest).writeTo(tmpDir.resolve("base.zip"));
    BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
    try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
        assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
        assertThat(bundle).hasFile("base/apex/x86_64.img").withContent("x86_64".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/x86_64.build_info.pb").withContent("x86_64.build_info".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/x86.img").withContent("x86".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/x86.build_info.pb").withContent("x86.build_info".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/arm64-v8a.img").withContent("arm64-v8a".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/arm64-v8a.build_info.pb").withContent("arm64-v8a.build_info".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/armeabi-v7a.img").withContent("armeabi-v7a".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/apex/armeabi-v7a.build_info.pb").withContent("armeabi-v7a.build_info".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/root/apex_manifest.json").withContent(apexManifest);
        assertThat(bundle).hasFile("base/apex.pb").withContent(apexConfig.toByteArray());
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) XmlNode(com.android.aapt.Resources.XmlNode) ApexImages(com.android.bundle.Files.ApexImages) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Test(org.junit.Test)

Example 79 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class BuildBundleCommandTest method validModule.

@Test
public void validModule() throws Exception {
    XmlNode manifest = androidManifest(PKG_NAME, withHasCode(true));
    ResourceTable resourceTable = new ResourceTableBuilder().addPackage(PKG_NAME).addDrawableResource("icon", "res/drawable/icon.png").build();
    Path module = new ZipBuilder().addFileWithContent(ZipPath.create("assets/anything.dat"), "any".getBytes(UTF_8)).addFileWithContent(ZipPath.create("dex/classes.dex"), "dex".getBytes(UTF_8)).addFileWithContent(ZipPath.create("lib/x86/libX.so"), "native".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("manifest/AndroidManifest.xml"), manifest).addFileWithContent(ZipPath.create("res/drawable/icon.png"), "image".getBytes(UTF_8)).addFileWithContent(ZipPath.create("root/anything2.dat"), "any2".getBytes(UTF_8)).addFileWithProtoContent(ZipPath.create("resources.pb"), resourceTable).writeTo(tmpDir.resolve("base.zip"));
    BuildBundleCommand.builder().setOutputPath(bundlePath).setModulesPaths(ImmutableList.of(module)).build().execute();
    try (ZipFile bundle = new ZipFile(bundlePath.toFile())) {
        assertThat(bundle).hasFile("base/assets/anything.dat").withContent("any".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/dex/classes.dex").withContent("dex".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/lib/x86/libX.so").withContent("native".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/manifest/AndroidManifest.xml").withContent(manifest.toByteArray());
        assertThat(bundle).hasFile("base/res/drawable/icon.png").withContent("image".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/root/anything2.dat").withContent("any2".getBytes(UTF_8));
        assertThat(bundle).hasFile("base/resources.pb").withContent(resourceTable.toByteArray());
    }
}
Also used : Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) XmlNode(com.android.aapt.Resources.XmlNode) ZipFile(java.util.zip.ZipFile) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) Test(org.junit.Test)

Example 80 with XmlNode

use of com.android.aapt.Resources.XmlNode in project bundletool by google.

the class DumpManagerTest method dumpManifest_moduleNotBase.

@Test
public void dumpManifest_moduleNotBase() throws Exception {
    XmlNode manifestBase = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").addAttribute(XmlAttribute.newBuilder().setName("package").setValue("base"))).build();
    XmlNode manifestModule = XmlNode.newBuilder().setElement(XmlElement.newBuilder().setName("manifest").addAttribute(XmlAttribute.newBuilder().setName("package").setValue("module"))).build();
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(manifestBase)).addModule("module", module -> module.setManifest(manifestModule)).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DumpCommand.builder().setBundlePath(bundlePath).setDumpTarget(DumpTarget.MANIFEST).setModuleName("module").setOutputStream(new PrintStream(outputStream)).build().execute();
    assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo(String.format("<manifest package=\"module\" split=\"module\"/>%n"));
}
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)

Aggregations

XmlNode (com.android.aapt.Resources.XmlNode)99 Test (org.junit.Test)91 XmlElement (com.android.aapt.Resources.XmlElement)28 AppBundle (com.android.tools.build.bundletool.model.AppBundle)27 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)23 Truth.assertThat (com.google.common.truth.Truth.assertThat)23 RunWith (org.junit.runner.RunWith)23 ResourceTable (com.android.aapt.Resources.ResourceTable)21 ImmutableList (com.google.common.collect.ImmutableList)21 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)16 Nullable (javax.annotation.Nullable)16 Theories (org.junit.experimental.theories.Theories)16 ZipFile (java.util.zip.ZipFile)12 FileReference (com.android.aapt.Resources.FileReference)10 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)10 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)9 Attribute (com.android.aapt.Resources.Attribute)9 Symbol (com.android.aapt.Resources.Attribute.Symbol)9 CompoundValue (com.android.aapt.Resources.CompoundValue)9 ConfigValue (com.android.aapt.Resources.ConfigValue)9