Search in sources :

Example 26 with ApkDescription

use of com.android.bundle.Commands.ApkDescription in project bundletool by google.

the class BuildApksManagerTest method pinningOfManifestReachableResources_enabledSince_0_8_1.

@Test
public void pinningOfManifestReachableResources_enabledSince_0_8_1() throws Exception {
    AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("res/drawable-mdpi/manifest_image.jpg").addFile("res/drawable-hdpi/manifest_image.jpg").addFile("res/drawable-mdpi/other_image.jpg").addFile("res/drawable-hdpi/other_image.jpg").setManifest(androidManifest("com.test.app", withAppIcon(/* ID of "drawable/manifest_image" */
    0x7f010000))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("manifest_image", ImmutableMap.of(/* mdpi */
    160, "res/drawable-mdpi/manifest_image.jpg", /* hdpi */
    240, "res/drawable-hdpi/manifest_image.jpg")).addDrawableResourceForMultipleDensities("other_image", ImmutableMap.of(/* mdpi */
    160, "res/drawable-mdpi/other_image.jpg", /* hdpi */
    240, "res/drawable-hdpi/other_image.jpg")).build())).setBundleConfig(BundleConfigBuilder.create().setVersion("0.8.1").build()).build();
    TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
    buildApksManager.execute();
    ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
    BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
    ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
    ImmutableList<ApkDescription> splitApks = apkDescriptions(splitApkVariants);
    // The lowest density (mdpi) of "drawable/manifest_reachable_image" is in the master.
    ImmutableList<ApkDescription> masterSplits = splitApks.stream().filter(apkDesc -> apkDesc.getSplitApkMetadata().getIsMasterSplit()).collect(toImmutableList());
    assertThat(masterSplits).isNotEmpty();
    for (ApkDescription masterSplit : masterSplits) {
        assertThat(filesInApk(masterSplit, apkSetFile)).contains("res/drawable-mdpi/manifest_image.jpg");
    }
    ImmutableList<ApkDescription> densitySplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasScreenDensityTargeting()).collect(toImmutableList());
    assertThat(densitySplits).isNotEmpty();
    for (ApkDescription densitySplit : densitySplits) {
        assertThat(filesInApk(densitySplit, apkSetFile)).doesNotContain("res/drawable-mdpi/manifest_image.jpg");
    }
}
Also used : Variant(com.android.bundle.Commands.Variant) TEST_LABEL_RESOURCE_ID(com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID) SYSTEM(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ApkSetUtils.parseTocFromFile(com.android.tools.build.bundletool.testing.ApkSetUtils.parseTocFromFile) TargetingUtils.alternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeLanguageTargeting) Bundletool(com.android.bundle.Config.Bundletool) ARM64_V8A(com.android.bundle.Targeting.Abi.AbiAlias.ARM64_V8A) AssetModulesConfig(com.android.bundle.Config.AssetModulesConfig) Map(java.util.Map) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) TestUtils.filesUnderPath(com.android.tools.build.bundletool.testing.TestUtils.filesUnderPath) Path(java.nio.file.Path) SourceStamp(com.android.tools.build.bundletool.model.SourceStamp) ManifestProtoUtils.withTitle(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withTitle) TargetingUtils.nativeDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting) ASSETS_DIRECTORY(com.android.tools.build.bundletool.model.BundleModule.ASSETS_DIRECTORY) DIRECTORY(com.android.tools.build.bundletool.commands.BuildApksCommand.OutputFormat.DIRECTORY) DeviceFactory.sdkVersion(com.android.tools.build.bundletool.testing.DeviceFactory.sdkVersion) ApkSet(com.android.bundle.Commands.ApkSet) BundleConfig(com.android.bundle.Config.BundleConfig) TextureCompressionFormatTargeting(com.android.bundle.Targeting.TextureCompressionFormatTargeting) TargetingUtils.variantAbiTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantAbiTargeting) SystemApkOption(com.android.tools.build.bundletool.commands.BuildApksCommand.SystemApkOption) ManifestProtoUtils.androidManifestForFeature(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForFeature) TargetingUtils.assetsDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting) CodeTransparency(com.android.bundle.CodeTransparencyOuterClass.CodeTransparency) SystemApkMetadata(com.android.bundle.Commands.SystemApkMetadata) STAMP_SOURCE_METADATA_KEY(com.android.tools.build.bundletool.model.SourceStamp.STAMP_SOURCE_METADATA_KEY) MDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI) ApexManifest(com.android.apex.ApexManifestProto.ApexManifest) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ManifestProtoUtils.withInstantOnDemandDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstantOnDemandDelivery) RunWith(org.junit.runner.RunWith) MDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.MDPI_VALUE) SdkVersion(com.android.bundle.Targeting.SdkVersion) TEXTURE_COMPRESSION_FORMAT(com.android.tools.build.bundletool.model.OptimizationDimension.TEXTURE_COMPRESSION_FORMAT) DeviceFactory.mergeSpecs(com.android.tools.build.bundletool.testing.DeviceFactory.mergeSpecs) StandaloneApkMetadata(com.android.bundle.Commands.StandaloneApkMetadata) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) Theories(org.junit.experimental.theories.Theories) ResultUtils.instantApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.instantApkVariants) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ApkDescription(com.android.bundle.Commands.ApkDescription) Before(org.junit.Before) X86(com.android.bundle.Targeting.Abi.AbiAlias.X86) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) IOException(java.io.IOException) Test(org.junit.Test) Correspondence(com.google.common.truth.Correspondence) ALL_MODULES_SHORTCUT(com.android.tools.build.bundletool.commands.ExtractApksCommand.ALL_MODULES_SHORTCUT) ResultUtils.apexApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.apexApkVariants) AppBundle(com.android.tools.build.bundletool.model.AppBundle) CodeRelatedFile(com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile) X509Certificate(java.security.cert.X509Certificate) ManifestProtoUtils.withNativeActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withNativeActivity) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Maps.transformValues(com.google.common.collect.Maps.transformValues) ManifestProtoUtils.withInstallLocation(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallLocation) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) AssetsDirectoryTargeting(com.android.bundle.Targeting.AssetsDirectoryTargeting) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) ManifestProtoUtils.withOnDemandDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withOnDemandDelivery) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) PERSISTENT(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.PERSISTENT) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) KeyStore(java.security.KeyStore) InstantMetadata(com.android.bundle.Commands.InstantMetadata) Collectors(java.util.stream.Collectors) ScreenDensity(com.android.bundle.Targeting.ScreenDensity) InvalidVersionCodeException(com.android.tools.build.bundletool.model.exceptions.InvalidVersionCodeException) DefaultTargetingValue(com.android.bundle.Commands.DefaultTargetingValue) ManifestProtoUtils.withOnDemandAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withOnDemandAttribute) CertificateHelper(com.android.tools.build.bundletool.model.utils.CertificateHelper) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) ApkSetUtils(com.android.tools.build.bundletool.testing.ApkSetUtils) PermanentlyFusedModule(com.android.bundle.Commands.PermanentlyFusedModule) FilePreconditions(com.android.tools.build.bundletool.model.utils.files.FilePreconditions) ManifestProtoUtils.withMaxSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMaxSdkVersion) BundleType(com.android.bundle.Config.BundleConfig.BundleType) DeviceFactory.locales(com.android.tools.build.bundletool.testing.DeviceFactory.locales) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) TargetingUtils.alternativeTextureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeTextureCompressionTargeting) TargetingUtils.variantSdkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantSdkTargeting) ResultUtils.standaloneApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.standaloneApkVariants) ApkModifier(com.android.tools.build.bundletool.model.ApkModifier) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) Hashing(com.google.common.hash.Hashing) TargetingUtils.moduleDeviceGroupsTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.moduleDeviceGroupsTargeting) ManifestProtoUtils.withDeviceGroupsCondition(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withDeviceGroupsCondition) TargetingUtils.toAbi(com.android.tools.build.bundletool.testing.TargetingUtils.toAbi) Inject(javax.inject.Inject) ModuleMetadata(com.android.bundle.Commands.ModuleMetadata) ImmutableList(com.google.common.collect.ImmutableList) Charset(java.nio.charset.Charset) ManifestProtoUtils.withSplitNameService(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameService) CharSource(com.google.common.io.CharSource) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) LDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.LDPI) CertificateFactory(com.android.tools.build.bundletool.testing.CertificateFactory) TargetingUtils.sdkVersionFrom(com.android.tools.build.bundletool.testing.TargetingUtils.sdkVersionFrom) TestData(com.android.tools.build.bundletool.TestData) Truth.assertThat(com.google.common.truth.Truth.assertThat) FileUtils(com.android.tools.build.bundletool.testing.FileUtils) TargetingUtils.nativeLibraries(com.android.tools.build.bundletool.testing.TargetingUtils.nativeLibraries) Ignore(org.junit.Ignore) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) ApkVerifier(com.android.apksig.ApkVerifier) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) KeyPair(java.security.KeyPair) Value(com.android.bundle.Config.SplitDimension.Value) UNIVERSAL(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.UNIVERSAL) ResourcesTableFactory.locale(com.android.tools.build.bundletool.testing.ResourcesTableFactory.locale) TargetingUtils.textureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionTargeting) DeviceFactory.abis(com.android.tools.build.bundletool.testing.DeviceFactory.abis) TargetingUtils.variantMultiAbiTargetingFromAllTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantMultiAbiTargetingFromAllTargeting) DeliveryType(com.android.bundle.Commands.DeliveryType) ManifestProtoUtils.withUsesSplit(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withUsesSplit) ResourcesTableFactory.resourceTableWithTestLabel(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTableWithTestLabel) Version(com.android.tools.build.bundletool.model.version.Version) TruthZip(com.android.tools.build.bundletool.testing.truth.zip.TruthZip) Theory(org.junit.experimental.theories.Theory) KeyPairGenerator(java.security.KeyPairGenerator) ImmutableMultiset.toImmutableMultiset(com.google.common.collect.ImmutableMultiset.toImmutableMultiset) BundleToolVersion(com.android.tools.build.bundletool.model.version.BundleToolVersion) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ARMEABI_V7A(com.android.bundle.Targeting.Abi.AbiAlias.ARMEABI_V7A) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) ManifestProtoUtils.withInstallTimeRemovableElement(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeRemovableElement) Executors(java.util.concurrent.Executors) ManifestProtoUtils.withMinSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMinSdkVersion) ApexImages(com.android.bundle.Files.ApexImages) TargetingUtils.apexImageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apexImageTargeting) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) DeviceFactory.density(com.android.tools.build.bundletool.testing.DeviceFactory.density) TextureCompressionFormat(com.android.bundle.Targeting.TextureCompressionFormat) PrivateKey(java.security.PrivateKey) ByteStreams(com.google.common.io.ByteStreams) ManifestProtoUtils.withInstallTimeDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeDelivery) ResultUtils.systemApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.systemApkVariants) DEVELOPMENT_SDK_VERSION(com.android.tools.build.bundletool.model.AndroidManifest.DEVELOPMENT_SDK_VERSION) TargetingUtils.targetedApexImage(com.android.tools.build.bundletool.testing.TargetingUtils.targetedApexImage) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) TruthZip.assertThat(com.android.tools.build.bundletool.testing.truth.zip.TruthZip.assertThat) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Iterables(com.google.common.collect.Iterables) Optimizations(com.android.bundle.Config.Optimizations) ATC(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ATC) TargetingUtils.textureCompressionFormat(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionFormat) Component(dagger.Component) LANGUAGE(com.android.tools.build.bundletool.model.OptimizationDimension.LANGUAGE) ApkSetUtils.extractTocFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile) Closer(com.google.common.io.Closer) ImmutableMultiset(com.google.common.collect.ImmutableMultiset) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ResultUtils.splitApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.splitApkVariants) SplitApkMetadata(com.android.bundle.Commands.SplitApkMetadata) ANDROID_P_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_P_API_VERSION) ByteSource(com.google.common.io.ByteSource) CodeTransparencyTestUtils.createJwsToken(com.android.tools.build.bundletool.testing.CodeTransparencyTestUtils.createJwsToken) ANDROID_Q_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_Q_API_VERSION) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) AdbServer(com.android.tools.build.bundletool.device.AdbServer) StandaloneConfig(com.android.bundle.Config.StandaloneConfig) Int32Value(com.google.protobuf.Int32Value) DeviceFactory.deviceTier(com.android.tools.build.bundletool.testing.DeviceFactory.deviceTier) Files(java.nio.file.Files) ANDROID_N_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_N_API_VERSION) TargetingUtils.targetedNativeDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedNativeDirectory) TestCase.fail(junit.framework.TestCase.fail) FileOutputStream(java.io.FileOutputStream) X86_64(com.android.bundle.Targeting.Abi.AbiAlias.X86_64) BundleMetadata(com.android.tools.build.bundletool.model.BundleMetadata) ANDROID_M_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_M_API_VERSION) TargetingUtils.assets(com.android.tools.build.bundletool.testing.TargetingUtils.assets) File(java.io.File) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) ResultUtils.archivedApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.archivedApkVariants) Paths(java.nio.file.Paths) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Abi(com.android.bundle.Targeting.Abi) TargetingUtils.sdkVersionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.sdkVersionTargeting) ManifestProtoUtils.withAppIcon(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withAppIcon) Variant(com.android.bundle.Commands.Variant) TestUtils.extractAndroidManifest(com.android.tools.build.bundletool.testing.TestUtils.extractAndroidManifest) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) ManifestProtoUtils.androidManifestForAssetModule(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForAssetModule) TargetingUtils.mergeVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting) ManifestProtoUtils.withDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withDelivery) TargetingUtils.deviceTierTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.deviceTierTargeting) TargetingUtils.targetedAssetsDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedAssetsDirectory) After(org.junit.After) ManifestProtoUtils.withTargetSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withTargetSdkVersion) ImmutableMap(com.google.common.collect.ImmutableMap) FromDataPoints(org.junit.experimental.theories.FromDataPoints) List(java.util.List) Certificate(java.security.cert.Certificate) INSTANT(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.INSTANT) DataPoints(org.junit.experimental.theories.DataPoints) ABI(com.android.tools.build.bundletool.model.OptimizationDimension.ABI) ManifestProtoUtils.withCustomThemeActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withCustomThemeActivity) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) TestModule(com.android.tools.build.bundletool.testing.TestModule) BeforeClass(org.junit.BeforeClass) TargetingUtils.apexImages(com.android.tools.build.bundletool.testing.TargetingUtils.apexImages) BuildApksResult(com.android.bundle.Commands.BuildApksResult) DeviceTierTargeting(com.android.bundle.Targeting.DeviceTierTargeting) SdkVersionTargeting(com.android.bundle.Targeting.SdkVersionTargeting) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) MIPS(com.android.bundle.Targeting.Abi.AbiAlias.MIPS) ManifestProtoUtils.withInstant(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstant) ARCHIVE(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.ARCHIVE) Assert.assertNotNull(org.junit.Assert.assertNotNull) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ManifestProtoUtils.withFusingAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withFusingAttribute) TargetingUtils.apkMultiAbiTargetingFromAllTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkMultiAbiTargetingFromAllTargeting) ETC1_RGB8(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ETC1_RGB8) AssetModulesInfo(com.android.bundle.Commands.AssetModulesInfo) Maps(com.google.common.collect.Maps) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Rule(org.junit.Rule) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) AppBundle(com.android.tools.build.bundletool.model.AppBundle) ApkDescription(com.android.bundle.Commands.ApkDescription) ZipFile(java.util.zip.ZipFile) BuildApksResult(com.android.bundle.Commands.BuildApksResult) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) Test(org.junit.Test)

Example 27 with ApkDescription

use of com.android.bundle.Commands.ApkDescription in project bundletool by google.

the class BuildApksManagerTest method transparencyFilePropagatedAsExpected.

@Test
public void transparencyFilePropagatedAsExpected() throws Exception {
    String dexFilePath = "dex/classes.dex";
    byte[] dexFileInBaseModuleContent = TestData.readBytes("testdata/dex/classes.dex");
    byte[] dexFileInFeatureModuleContent = TestData.readBytes("testdata/dex/classes-other.dex");
    String libFilePath = "lib/x86_64/libsome.so";
    byte[] libFileInBaseModuleContent = new byte[] { 4, 5, 6 };
    CodeTransparency codeTransparency = CodeTransparency.newBuilder().addCodeRelatedFile(CodeRelatedFile.newBuilder().setType(CodeRelatedFile.Type.DEX).setPath("base/" + dexFilePath).setSha256(ByteSource.wrap(dexFileInBaseModuleContent).hash(Hashing.sha256()).toString())).addCodeRelatedFile(CodeRelatedFile.newBuilder().setType(CodeRelatedFile.Type.NATIVE_LIBRARY).setPath("base/" + libFilePath).setSha256(ByteSource.wrap(libFileInBaseModuleContent).hash(Hashing.sha256()).toString()).setApkPath(libFilePath)).addCodeRelatedFile(CodeRelatedFile.newBuilder().setType(CodeRelatedFile.Type.DEX).setPath("feature/" + dexFilePath).setSha256(ByteSource.wrap(dexFileInFeatureModuleContent).hash(Hashing.sha256()).toString())).build();
    Path bundlePath = tmpDir.resolve("bundle.aab");
    AppBundleBuilder appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.test.app", withMinSdkVersion(20))).setResourceTable(resourceTableWithTestLabel("Test feature")).addFile(dexFilePath, bundlePath, ZipPath.create("base/" + dexFilePath), dexFileInBaseModuleContent).addFile(libFilePath, bundlePath, ZipPath.create("base/" + libFilePath), libFileInBaseModuleContent).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64))))).addModule("feature", module -> module.setManifest(androidManifest("com.test.app", withDelivery(DeliveryType.ON_DEMAND), withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID))).addFile(dexFilePath, bundlePath, ZipPath.create("feature/" + dexFilePath), dexFileInFeatureModuleContent)).addMetadataFile(BundleMetadata.BUNDLETOOL_NAMESPACE, BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME, CharSource.wrap(createJwsToken(codeTransparency, certificate, privateKey)).asByteSource(Charset.defaultCharset()));
    TestComponent.useTestModule(this, createTestModuleBuilder().withOutputPath(outputFilePath).withAppBundle(appBundle.build()).build());
    buildApksManager.execute();
    ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
    BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
    ImmutableList<ApkDescription> splitApks = apkDescriptions(splitApkVariants(result));
    // Transparency file should be propagated to main split of the base module.
    ImmutableList<ApkDescription> mainSplitsOfBaseModule = splitApks.stream().filter(apk -> apk.getSplitApkMetadata().getSplitId().isEmpty() && apk.getSplitApkMetadata().getIsMasterSplit()).collect(toImmutableList());
    assertThat(mainSplitsOfBaseModule).hasSize(2);
    for (ApkDescription apk : mainSplitsOfBaseModule) {
        ZipFile zipFile = openZipFile(extractFromApkSetFile(apkSetFile, apk.getPath(), outputDir));
        assertThat(filesUnderPath(zipFile, ZipPath.create("META-INF"))).contains("META-INF/" + BundleMetadata.TRANSPARENCY_SIGNED_FILE_NAME);
    }
    // Other splits should not contain transparency file.
    ImmutableList<ApkDescription> otherSplits = splitApks.stream().filter(apk -> !apk.getSplitApkMetadata().getSplitId().isEmpty()).collect(toImmutableList());
    assertThat(otherSplits).hasSize(4);
    for (ApkDescription apk : otherSplits) {
        ZipFile zipFile = openZipFile(extractFromApkSetFile(apkSetFile, apk.getPath(), outputDir));
        assertThat(filesUnderPath(zipFile, ZipPath.create("META-INF"))).isEmpty();
    }
    // Because minSdkVersion < 21, bundle has a feature module and merging strategy is
    // MERGE_IF_NEEDED (default), transparency file should not be propagated to standalone APK.
    assertThat(standaloneApkVariants(result)).hasSize(1);
    ImmutableList<ApkDescription> standaloneApks = apkDescriptions(standaloneApkVariants(result).get(0));
    File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApks.get(0).getPath(), outputDir);
    ZipFile standaloneApkZip = openZipFile(standaloneApkFile);
    assertThat(filesUnderPath(standaloneApkZip, ZipPath.create("META-INF"))).isEmpty();
}
Also used : TestUtils.filesUnderPath(com.android.tools.build.bundletool.testing.TestUtils.filesUnderPath) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) TEST_LABEL_RESOURCE_ID(com.android.tools.build.bundletool.testing.ResourcesTableFactory.TEST_LABEL_RESOURCE_ID) SYSTEM(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ApkSetUtils.parseTocFromFile(com.android.tools.build.bundletool.testing.ApkSetUtils.parseTocFromFile) TargetingUtils.alternativeLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeLanguageTargeting) Bundletool(com.android.bundle.Config.Bundletool) ARM64_V8A(com.android.bundle.Targeting.Abi.AbiAlias.ARM64_V8A) AssetModulesConfig(com.android.bundle.Config.AssetModulesConfig) Map(java.util.Map) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) TestUtils.filesUnderPath(com.android.tools.build.bundletool.testing.TestUtils.filesUnderPath) Path(java.nio.file.Path) SourceStamp(com.android.tools.build.bundletool.model.SourceStamp) ManifestProtoUtils.withTitle(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withTitle) TargetingUtils.nativeDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.nativeDirectoryTargeting) ASSETS_DIRECTORY(com.android.tools.build.bundletool.model.BundleModule.ASSETS_DIRECTORY) DIRECTORY(com.android.tools.build.bundletool.commands.BuildApksCommand.OutputFormat.DIRECTORY) DeviceFactory.sdkVersion(com.android.tools.build.bundletool.testing.DeviceFactory.sdkVersion) ApkSet(com.android.bundle.Commands.ApkSet) BundleConfig(com.android.bundle.Config.BundleConfig) TextureCompressionFormatTargeting(com.android.bundle.Targeting.TextureCompressionFormatTargeting) TargetingUtils.variantAbiTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantAbiTargeting) SystemApkOption(com.android.tools.build.bundletool.commands.BuildApksCommand.SystemApkOption) ManifestProtoUtils.androidManifestForFeature(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForFeature) TargetingUtils.assetsDirectoryTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.assetsDirectoryTargeting) CodeTransparency(com.android.bundle.CodeTransparencyOuterClass.CodeTransparency) SystemApkMetadata(com.android.bundle.Commands.SystemApkMetadata) STAMP_SOURCE_METADATA_KEY(com.android.tools.build.bundletool.model.SourceStamp.STAMP_SOURCE_METADATA_KEY) MDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI) ApexManifest(com.android.apex.ApexManifestProto.ApexManifest) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ManifestProtoUtils.withInstantOnDemandDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstantOnDemandDelivery) RunWith(org.junit.runner.RunWith) MDPI_VALUE(com.android.tools.build.bundletool.model.utils.ResourcesUtils.MDPI_VALUE) SdkVersion(com.android.bundle.Targeting.SdkVersion) TEXTURE_COMPRESSION_FORMAT(com.android.tools.build.bundletool.model.OptimizationDimension.TEXTURE_COMPRESSION_FORMAT) DeviceFactory.mergeSpecs(com.android.tools.build.bundletool.testing.DeviceFactory.mergeSpecs) StandaloneApkMetadata(com.android.bundle.Commands.StandaloneApkMetadata) SigningConfiguration(com.android.tools.build.bundletool.model.SigningConfiguration) Theories(org.junit.experimental.theories.Theories) ResultUtils.instantApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.instantApkVariants) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ApkDescription(com.android.bundle.Commands.ApkDescription) Before(org.junit.Before) X86(com.android.bundle.Targeting.Abi.AbiAlias.X86) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) IOException(java.io.IOException) Test(org.junit.Test) Correspondence(com.google.common.truth.Correspondence) ALL_MODULES_SHORTCUT(com.android.tools.build.bundletool.commands.ExtractApksCommand.ALL_MODULES_SHORTCUT) ResultUtils.apexApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.apexApkVariants) AppBundle(com.android.tools.build.bundletool.model.AppBundle) CodeRelatedFile(com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile) X509Certificate(java.security.cert.X509Certificate) ManifestProtoUtils.withNativeActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withNativeActivity) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Maps.transformValues(com.google.common.collect.Maps.transformValues) ManifestProtoUtils.withInstallLocation(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallLocation) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) AssetsDirectoryTargeting(com.android.bundle.Targeting.AssetsDirectoryTargeting) TargetingUtils.languageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.languageTargeting) ManifestProtoUtils.withOnDemandDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withOnDemandDelivery) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) PERSISTENT(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.PERSISTENT) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) KeyStore(java.security.KeyStore) InstantMetadata(com.android.bundle.Commands.InstantMetadata) Collectors(java.util.stream.Collectors) ScreenDensity(com.android.bundle.Targeting.ScreenDensity) InvalidVersionCodeException(com.android.tools.build.bundletool.model.exceptions.InvalidVersionCodeException) DefaultTargetingValue(com.android.bundle.Commands.DefaultTargetingValue) ManifestProtoUtils.withOnDemandAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withOnDemandAttribute) CertificateHelper(com.android.tools.build.bundletool.model.utils.CertificateHelper) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) ApkSetUtils(com.android.tools.build.bundletool.testing.ApkSetUtils) PermanentlyFusedModule(com.android.bundle.Commands.PermanentlyFusedModule) FilePreconditions(com.android.tools.build.bundletool.model.utils.files.FilePreconditions) ManifestProtoUtils.withMaxSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMaxSdkVersion) BundleType(com.android.bundle.Config.BundleConfig.BundleType) DeviceFactory.locales(com.android.tools.build.bundletool.testing.DeviceFactory.locales) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) TargetingUtils.alternativeTextureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.alternativeTextureCompressionTargeting) TargetingUtils.variantSdkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantSdkTargeting) ResultUtils.standaloneApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.standaloneApkVariants) ApkModifier(com.android.tools.build.bundletool.model.ApkModifier) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) Hashing(com.google.common.hash.Hashing) TargetingUtils.moduleDeviceGroupsTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.moduleDeviceGroupsTargeting) ManifestProtoUtils.withDeviceGroupsCondition(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withDeviceGroupsCondition) TargetingUtils.toAbi(com.android.tools.build.bundletool.testing.TargetingUtils.toAbi) Inject(javax.inject.Inject) ModuleMetadata(com.android.bundle.Commands.ModuleMetadata) ImmutableList(com.google.common.collect.ImmutableList) Charset(java.nio.charset.Charset) ManifestProtoUtils.withSplitNameService(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameService) CharSource(com.google.common.io.CharSource) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) LDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.LDPI) CertificateFactory(com.android.tools.build.bundletool.testing.CertificateFactory) TargetingUtils.sdkVersionFrom(com.android.tools.build.bundletool.testing.TargetingUtils.sdkVersionFrom) TestData(com.android.tools.build.bundletool.TestData) Truth.assertThat(com.google.common.truth.Truth.assertThat) FileUtils(com.android.tools.build.bundletool.testing.FileUtils) TargetingUtils.nativeLibraries(com.android.tools.build.bundletool.testing.TargetingUtils.nativeLibraries) Ignore(org.junit.Ignore) InvalidCommandException(com.android.tools.build.bundletool.model.exceptions.InvalidCommandException) ApkVerifier(com.android.apksig.ApkVerifier) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) KeyPair(java.security.KeyPair) Value(com.android.bundle.Config.SplitDimension.Value) UNIVERSAL(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.UNIVERSAL) ResourcesTableFactory.locale(com.android.tools.build.bundletool.testing.ResourcesTableFactory.locale) TargetingUtils.textureCompressionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionTargeting) DeviceFactory.abis(com.android.tools.build.bundletool.testing.DeviceFactory.abis) TargetingUtils.variantMultiAbiTargetingFromAllTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.variantMultiAbiTargetingFromAllTargeting) DeliveryType(com.android.bundle.Commands.DeliveryType) ManifestProtoUtils.withUsesSplit(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withUsesSplit) ResourcesTableFactory.resourceTableWithTestLabel(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTableWithTestLabel) Version(com.android.tools.build.bundletool.model.version.Version) TruthZip(com.android.tools.build.bundletool.testing.truth.zip.TruthZip) Theory(org.junit.experimental.theories.Theory) KeyPairGenerator(java.security.KeyPairGenerator) ImmutableMultiset.toImmutableMultiset(com.google.common.collect.ImmutableMultiset.toImmutableMultiset) BundleToolVersion(com.android.tools.build.bundletool.model.version.BundleToolVersion) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ARMEABI_V7A(com.android.bundle.Targeting.Abi.AbiAlias.ARMEABI_V7A) LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) ManifestProtoUtils.withInstallTimeRemovableElement(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeRemovableElement) Executors(java.util.concurrent.Executors) ManifestProtoUtils.withMinSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMinSdkVersion) ApexImages(com.android.bundle.Files.ApexImages) TargetingUtils.apexImageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apexImageTargeting) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) DeviceFactory.density(com.android.tools.build.bundletool.testing.DeviceFactory.density) TextureCompressionFormat(com.android.bundle.Targeting.TextureCompressionFormat) PrivateKey(java.security.PrivateKey) ByteStreams(com.google.common.io.ByteStreams) ManifestProtoUtils.withInstallTimeDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeDelivery) ResultUtils.systemApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.systemApkVariants) DEVELOPMENT_SDK_VERSION(com.android.tools.build.bundletool.model.AndroidManifest.DEVELOPMENT_SDK_VERSION) TargetingUtils.targetedApexImage(com.android.tools.build.bundletool.testing.TargetingUtils.targetedApexImage) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) TruthZip.assertThat(com.android.tools.build.bundletool.testing.truth.zip.TruthZip.assertThat) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Iterables(com.google.common.collect.Iterables) Optimizations(com.android.bundle.Config.Optimizations) ATC(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ATC) TargetingUtils.textureCompressionFormat(com.android.tools.build.bundletool.testing.TargetingUtils.textureCompressionFormat) Component(dagger.Component) LANGUAGE(com.android.tools.build.bundletool.model.OptimizationDimension.LANGUAGE) ApkSetUtils.extractTocFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile) Closer(com.google.common.io.Closer) ImmutableMultiset(com.google.common.collect.ImmutableMultiset) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) ResultUtils.splitApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.splitApkVariants) SplitApkMetadata(com.android.bundle.Commands.SplitApkMetadata) ANDROID_P_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_P_API_VERSION) ByteSource(com.google.common.io.ByteSource) CodeTransparencyTestUtils.createJwsToken(com.android.tools.build.bundletool.testing.CodeTransparencyTestUtils.createJwsToken) ANDROID_Q_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_Q_API_VERSION) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) AdbServer(com.android.tools.build.bundletool.device.AdbServer) StandaloneConfig(com.android.bundle.Config.StandaloneConfig) Int32Value(com.google.protobuf.Int32Value) DeviceFactory.deviceTier(com.android.tools.build.bundletool.testing.DeviceFactory.deviceTier) Files(java.nio.file.Files) ANDROID_N_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_N_API_VERSION) TargetingUtils.targetedNativeDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedNativeDirectory) TestCase.fail(junit.framework.TestCase.fail) FileOutputStream(java.io.FileOutputStream) X86_64(com.android.bundle.Targeting.Abi.AbiAlias.X86_64) BundleMetadata(com.android.tools.build.bundletool.model.BundleMetadata) ANDROID_M_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_M_API_VERSION) TargetingUtils.assets(com.android.tools.build.bundletool.testing.TargetingUtils.assets) File(java.io.File) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) ResultUtils.archivedApkVariants(com.android.tools.build.bundletool.model.utils.ResultUtils.archivedApkVariants) Paths(java.nio.file.Paths) FakeAdbServer(com.android.tools.build.bundletool.testing.FakeAdbServer) Abi(com.android.bundle.Targeting.Abi) TargetingUtils.sdkVersionTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.sdkVersionTargeting) ManifestProtoUtils.withAppIcon(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withAppIcon) Variant(com.android.bundle.Commands.Variant) TestUtils.extractAndroidManifest(com.android.tools.build.bundletool.testing.TestUtils.extractAndroidManifest) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) ManifestProtoUtils.androidManifestForAssetModule(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForAssetModule) TargetingUtils.mergeVariantTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeVariantTargeting) ManifestProtoUtils.withDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withDelivery) TargetingUtils.deviceTierTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.deviceTierTargeting) TargetingUtils.targetedAssetsDirectory(com.android.tools.build.bundletool.testing.TargetingUtils.targetedAssetsDirectory) After(org.junit.After) ManifestProtoUtils.withTargetSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withTargetSdkVersion) ImmutableMap(com.google.common.collect.ImmutableMap) FromDataPoints(org.junit.experimental.theories.FromDataPoints) List(java.util.List) Certificate(java.security.cert.Certificate) INSTANT(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.INSTANT) DataPoints(org.junit.experimental.theories.DataPoints) ABI(com.android.tools.build.bundletool.model.OptimizationDimension.ABI) ManifestProtoUtils.withCustomThemeActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withCustomThemeActivity) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) TestModule(com.android.tools.build.bundletool.testing.TestModule) BeforeClass(org.junit.BeforeClass) TargetingUtils.apexImages(com.android.tools.build.bundletool.testing.TargetingUtils.apexImages) BuildApksResult(com.android.bundle.Commands.BuildApksResult) DeviceTierTargeting(com.android.bundle.Targeting.DeviceTierTargeting) SdkVersionTargeting(com.android.bundle.Targeting.SdkVersionTargeting) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) MIPS(com.android.bundle.Targeting.Abi.AbiAlias.MIPS) ManifestProtoUtils.withInstant(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstant) ARCHIVE(com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.ARCHIVE) Assert.assertNotNull(org.junit.Assert.assertNotNull) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) ManifestProtoUtils.withFusingAttribute(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withFusingAttribute) TargetingUtils.apkMultiAbiTargetingFromAllTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkMultiAbiTargetingFromAllTargeting) ETC1_RGB8(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias.ETC1_RGB8) AssetModulesInfo(com.android.bundle.Commands.AssetModulesInfo) Maps(com.google.common.collect.Maps) AbiAlias(com.android.bundle.Targeting.Abi.AbiAlias) Rule(org.junit.Rule) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) ApkDescription(com.android.bundle.Commands.ApkDescription) ZipFile(java.util.zip.ZipFile) BuildApksResult(com.android.bundle.Commands.BuildApksResult) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) CodeTransparency(com.android.bundle.CodeTransparencyOuterClass.CodeTransparency) ApkSetUtils.parseTocFromFile(com.android.tools.build.bundletool.testing.ApkSetUtils.parseTocFromFile) CodeRelatedFile(com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile) 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)

Example 28 with ApkDescription

use of com.android.bundle.Commands.ApkDescription in project bundletool by google.

the class BuildSdkApksManagerTest method manifestIsMutated.

@Test
public void manifestIsMutated() throws Exception {
    Integer versionCode = 1253;
    execute(new SdkBundleBuilder().setVersionCode(versionCode).build());
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    Variant variant = result.getVariant(0);
    ApkDescription apkDescription = variant.getApkSet(0).getApkDescription(0);
    File apkFile = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), tmpDir);
    AndroidManifest manifest = extractAndroidManifest(apkFile, tmpDir);
    assertThat(manifest.getMinSdkVersion()).hasValue(SDK_SANDBOX_MIN_VERSION);
    assertThat(manifest.getManifestRoot().getElement().getAndroidAttribute(VERSION_NAME_RESOURCE_ID).get().getValueAsString()).isEqualTo("15.0.5");
    assertThat(manifest.getManifestRoot().getElement().getAndroidAttribute(VERSION_CODE_RESOURCE_ID).get().getValueAsDecimalInteger()).isEqualTo(versionCode);
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) Variant(com.android.bundle.Commands.Variant) ApkDescription(com.android.bundle.Commands.ApkDescription) ZipFile(java.util.zip.ZipFile) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) TestUtils.extractAndroidManifest(com.android.tools.build.bundletool.testing.TestUtils.extractAndroidManifest) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) ApkSetUtils.extractTocFromSdkApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromSdkApkSetFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) Test(org.junit.Test)

Example 29 with ApkDescription

use of com.android.bundle.Commands.ApkDescription in project bundletool by google.

the class BuildSdkApksManagerTest method apksSigned.

@Test
public void apksSigned() throws Exception {
    execute(new SdkBundleBuilder().build());
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    Variant variant = result.getVariant(0);
    ApkDescription apkDescription = variant.getApkSet(0).getApkDescription(0);
    File apkFile = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), tmpDir);
    ApkVerifier.Result verifierResult = new ApkVerifier.Builder(apkFile).build().verify();
    assertThat(verifierResult.isVerified()).isTrue();
    assertThat(verifierResult.getSignerCertificates()).containsExactly(certificate);
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) Variant(com.android.bundle.Commands.Variant) ApkDescription(com.android.bundle.Commands.ApkDescription) ZipFile(java.util.zip.ZipFile) ApkVerifier(com.android.apksig.ApkVerifier) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) ApkSetUtils.extractTocFromSdkApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromSdkApkSetFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) Test(org.junit.Test)

Example 30 with ApkDescription

use of com.android.bundle.Commands.ApkDescription in project bundletool by google.

the class BuildSdkApksManagerTest method sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged.

@Test
public void sdkManifestMutation_highMinSdkVersion_minSdkVersionUnchanged() throws Exception {
    SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withMinSdkVersion(SDK_SANDBOX_MIN_VERSION + 5), withSdkLibraryElement("20"), withMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME, "12"))).build()).build();
    execute(sdkBundle);
    ZipFile apkSetFile = new ZipFile(outputFilePath.toFile());
    BuildSdkApksResult result = extractTocFromSdkApkSetFile(apkSetFile, tmpDir);
    Variant variant = result.getVariant(0);
    ApkDescription apkDescription = variant.getApkSet(0).getApkDescription(0);
    File apkFile = extractFromApkSetFile(apkSetFile, apkDescription.getPath(), tmpDir);
    AndroidManifest manifest = extractAndroidManifest(apkFile, tmpDir);
    assertThat(manifest.getMinSdkVersion()).hasValue(SDK_SANDBOX_MIN_VERSION + 5);
}
Also used : BuildSdkApksResult(com.android.bundle.Commands.BuildSdkApksResult) Variant(com.android.bundle.Commands.Variant) ApkDescription(com.android.bundle.Commands.ApkDescription) ZipFile(java.util.zip.ZipFile) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) TestUtils.extractAndroidManifest(com.android.tools.build.bundletool.testing.TestUtils.extractAndroidManifest) SdkBundleBuilder(com.android.tools.build.bundletool.testing.SdkBundleBuilder) ApkSetUtils.extractTocFromSdkApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromSdkApkSetFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) ApkSetUtils.extractFromApkSetFile(com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile) Test(org.junit.Test)

Aggregations

ApkDescription (com.android.bundle.Commands.ApkDescription)62 ZipFile (java.util.zip.ZipFile)57 Test (org.junit.Test)56 BuildApksResult (com.android.bundle.Commands.BuildApksResult)54 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)54 File (java.io.File)54 Variant (com.android.bundle.Commands.Variant)52 AppBundle (com.android.tools.build.bundletool.model.AppBundle)51 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)51 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)50 Path (java.nio.file.Path)49 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)48 ZipPath (com.android.tools.build.bundletool.model.ZipPath)48 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)47 ApkSet (com.android.bundle.Commands.ApkSet)47 ApkSetUtils.parseTocFromFile (com.android.tools.build.bundletool.testing.ApkSetUtils.parseTocFromFile)47 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)47 TestUtils.extractAndroidManifest (com.android.tools.build.bundletool.testing.TestUtils.extractAndroidManifest)47 ApkVerifier (com.android.apksig.ApkVerifier)46 BundleConfigBuilder (com.android.tools.build.bundletool.testing.BundleConfigBuilder)46