Search in sources :

Example 31 with AppBundleSerializer

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

the class BuildApksPreprocessingTest method renderscript32Bit_64BitStandaloneAndSplitApksFilteredOut.

@Test
public void renderscript32Bit_64BitStandaloneAndSplitApksFilteredOut() throws Exception {
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("dex/classes.dex").addFile("assets/script.bc").addFile("lib/armeabi-v7a/libfoo.so").addFile("lib/arm64-v8a/libfoo.so").setManifest(androidManifest("com.test.app", withMinSdkVersion(14))).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi-v7a", nativeDirectoryTargeting(ARMEABI_V7A)), targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A))))).setBundleConfig(BundleConfigBuilder.create().setUncompressNativeLibraries(false).build()).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
    command.execute();
    BuildApksResult result;
    try (ZipFile apkSetFile = new ZipFile(outputFilePath.toFile())) {
        result = extractTocFromApkSetFile(apkSetFile, outputDir);
    }
    assertThat(standaloneApkVariants(result)).hasSize(1);
    assertThat(standaloneApkVariants(result).get(0).getTargeting().getAbiTargeting()).isEqualTo(abiTargeting(ARMEABI_V7A));
    assertThat(splitApkVariants(result)).hasSize(1);
    ImmutableSet<AbiTargeting> abiTargetings = splitApkVariants(result).get(0).getApkSetList().stream().map(ApkSet::getApkDescriptionList).flatMap(list -> list.stream().map(ApkDescription::getTargeting)).map(ApkTargeting::getAbiTargeting).collect(toImmutableSet());
    assertThat(abiTargetings).containsExactly(AbiTargeting.getDefaultInstance(), abiTargeting(ARMEABI_V7A));
}
Also used : AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) BuildApksResult(com.android.bundle.Commands.BuildApksResult) AbiTargeting(com.android.bundle.Targeting.AbiTargeting) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) Test(org.junit.Test)

Example 32 with AppBundleSerializer

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

the class BuildApksPreprocessingTest method buildApksCommand_overridesAssetModuleCompression.

@Test
public void buildApksCommand_overridesAssetModuleCompression() throws Exception {
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("dex/classes.dex", DUMMY_CONTENT).addFile("assets/images/image.jpg", DUMMY_CONTENT).setManifest(androidManifest("com.test.app", withMinSdkVersion(15), withMaxSdkVersion(27))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("asset_module", module -> module.setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery())).addFile("assets/textures/texture.etc", DUMMY_CONTENT)).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
    command.execute();
    try (ZipFile apkSetFile = new ZipFile(outputFilePath.toFile())) {
        BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
        // Standalone variant.
        ImmutableList<Variant> standaloneVariants = standaloneApkVariants(result);
        assertThat(standaloneVariants).hasSize(1);
        Variant standaloneVariant = standaloneVariants.get(0);
        assertThat(standaloneVariant.getApkSetList()).hasSize(1);
        ApkSet standaloneApk = standaloneVariant.getApkSet(0);
        assertThat(standaloneApk.getApkDescriptionList()).hasSize(1);
        assertThat(apkSetFile).hasFile(standaloneApk.getApkDescription(0).getPath());
        File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApk.getApkDescription(0).getPath(), outputDir);
        try (ZipFile apkZip = new ZipFile(standaloneApkFile)) {
            assertThat(apkZip).hasFile("classes.dex").thatIsCompressed();
            assertThat(apkZip).hasFile("assets/images/image.jpg").thatIsCompressed();
            assertThat(apkZip).hasFile("assets/textures/texture.etc").thatIsUncompressed();
        }
        // L+ assets.
        assertThat(result.getAssetSliceSetCount()).isEqualTo(1);
        AssetSliceSet assetSlice = result.getAssetSliceSet(0);
        assertThat(assetSlice.getApkDescriptionCount()).isEqualTo(1);
        File apkFile = extractFromApkSetFile(apkSetFile, assetSlice.getApkDescription(0).getPath(), outputDir);
        try (ZipFile apkZip = new ZipFile(apkFile)) {
            assertThat(apkZip).hasFile("assets/textures/texture.etc").thatIsUncompressed();
        }
    }
}
Also used : TEST_LABEL_RESOURCE_ID(com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) Variant(com.android.bundle.Commands.Variant) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ManifestProtoUtils.androidManifestForAssetModule(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForAssetModule) TargetingUtils.abiTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.abiTargeting) LocalTestingPreprocessor(com.android.tools.build.bundletool.preprocessors.LocalTestingPreprocessor) ARM64_V8A(com.android.bundle.Targeting.Abi.AbiAlias.ARM64_V8A) ResourcesTableFactory.resourceTableWithTestLabel(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTableWithTestLabel) ZipFile(java.util.zip.ZipFile) Path(java.nio.file.Path) ManifestProtoUtils.withTitle(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withTitle) ImmutableSet(com.google.common.collect.ImmutableSet) TargetingUtils.nativeDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ARMEABI_V7A(com.android.bundle.Targeting.Abi.AbiAlias.ARMEABI_V7A) ManifestProtoUtils.withMinSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMinSdkVersion) UncheckedIOException(java.io.UncheckedIOException) ApkSet(com.android.bundle.Commands.ApkSet) List(java.util.List) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) ManifestProtoUtils.withInstallTimeDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeDelivery) ManifestProtoUtils.androidManifestForFeature(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForFeature) ManifestProtoUtils.withMaxSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMaxSdkVersion) TruthZip.assertThat(com.android.tools.build.bundletool.testing.truth.zip.TruthZip.assertThat) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) AbiTargeting(com.android.bundle.Targeting.AbiTargeting) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ResultUtils.standaloneApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.standaloneApkVariants) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) RunWith(org.junit.runner.RunWith) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ApkSetUtils.extractTocFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ApkDescription(com.android.bundle.Commands.ApkDescription) ResultUtils.splitApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.splitApkVariants) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Before(org.junit.Before) PrintStream(java.io.PrintStream) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ManifestProtoUtils.withFusingAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withFusingAttribute) TargetingUtils.targetedNativeDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedNativeDirectory) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) IOException(java.io.IOException) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) File(java.io.File) Aapt2Helper(com.android.tools.build.bundletool.testing.Aapt2Helper) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) TargetingUtils.nativeLibraries(com.android.tools.build.bundletool.testing.TargetingUtils.nativeLibraries) Rule(org.junit.Rule) XmlNode(com.android.aapt.Resources.XmlNode) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) Variant(com.android.bundle.Commands.Variant) ApkSet(com.android.bundle.Commands.ApkSet) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) BuildApksResult(com.android.bundle.Commands.BuildApksResult) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) ZipFile(java.util.zip.ZipFile) ApkSetUtils.extractTocFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile) File(java.io.File) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) Test(org.junit.Test)

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