Search in sources :

Example 46 with Variant

use of com.android.bundle.Commands.Variant 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)

Example 47 with Variant

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

the class GetSizeCommandTest method getSizeTotalInternal_multipleDimensions.

@Test
public void getSizeTotalInternal_multipleDimensions() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkDensityTargeting(LDPI, ImmutableSet.of(MDPI)), ZipPath.create("base-ldpi.apk"), /* isMasterSplit= */
    false), createApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(LDPI)), ZipPath.create("base-mdpi.apk"), /* isMasterSplit= */
    false)));
    Variant preLVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(15), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(ARMEABI, ImmutableSet.of(X86))), ApkTargeting.getDefaultInstance(), ZipPath.create("preL.apk"));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addVariant(preLVariant).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ConfigurationSizes configurationSizes = GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDimensions(ImmutableSet.of(Dimension.SDK, Dimension.ABI, Dimension.LANGUAGE, Dimension.SCREEN_DENSITY)).build().getSizeTotalInternal();
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setSdkVersion("21-").setScreenDensity("LDPI").build(), 2 * compressedApkSize, SizeConfiguration.builder().setSdkVersion("21-").setScreenDensity("MDPI").build(), 2 * compressedApkSize, SizeConfiguration.builder().setSdkVersion("15-20").setAbi("armeabi").build(), compressedApkSize);
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setSdkVersion("21-").setScreenDensity("LDPI").build(), 2 * compressedApkSize, SizeConfiguration.builder().setSdkVersion("21-").setScreenDensity("MDPI").build(), 2 * compressedApkSize, SizeConfiguration.builder().setSdkVersion("15-20").setAbi("armeabi").build(), compressedApkSize);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) Test(org.junit.Test)

Example 48 with Variant

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

the class GetSizeCommandTest method getSizeTotal_withDimensionsAndDeviceSpec.

@Test
public void getSizeTotal_withDimensionsAndDeviceSpec() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkDensityTargeting(LDPI, ImmutableSet.of(MDPI)), ZipPath.create("base-ldpi.apk"), /* isMasterSplit= */
    false), createApkDescription(apkDensityTargeting(MDPI, ImmutableSet.of(LDPI)), ZipPath.create("base-mdpi.apk"), /* isMasterSplit= */
    false), createApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), ZipPath.create("base-x86.apk"), /* isMasterSplit= */
    false), createApkDescription(apkAbiTargeting(X86_64, ImmutableSet.of(X86)), ZipPath.create("base-x86_64.apk"), /* isMasterSplit= */
    false)));
    Variant preLVariant = standaloneVariant(mergeVariantTargeting(variantSdkTargeting(sdkVersionFrom(15), ImmutableSet.of(sdkVersionFrom(21))), variantAbiTargeting(X86), variantDensityTargeting(LDPI)), ApkTargeting.getDefaultInstance(), ZipPath.create("preL.apk"));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addVariant(preLVariant).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDeviceSpec(DeviceSpec.newBuilder().setScreenDensity(124).addSupportedAbis("x86").build()).setDimensions(ImmutableSet.of(Dimension.ABI, Dimension.SCREEN_DENSITY)).build().getSizeTotal(new PrintStream(outputStream));
    assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo("ABI,SCREEN_DENSITY,MIN,MAX" + CRLF + String.format("x86,124,%d,%d", compressedApkSize, 3 * compressedApkSize) + CRLF);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) PrintStream(java.io.PrintStream) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 49 with Variant

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

the class GetSizeCommandTest method getSizeTotalInternal_singleSplitVariant.

@Test
public void getSizeTotalInternal_singleSplitVariant() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), ZipPath.create("base-x86.apk"), /* isMasterSplit= */
    false), createApkDescription(apkAbiTargeting(X86_64, ImmutableSet.of(X86)), ZipPath.create("base-x86_64.apk"), /* isMasterSplit= */
    false)));
    ZipBuilder archiveBuilder = new ZipBuilder();
    archiveBuilder.addFileWithContent(ZipPath.create("base-master.apk"), DUMMY_BYTES);
    archiveBuilder.addFileWithContent(ZipPath.create("base-x86.apk"), DUMMY_BYTES, // APK stored uncompressed in the APKs zip.
    EntryOption.UNCOMPRESSED);
    archiveBuilder.addFileWithContent(ZipPath.create("base-x86_64.apk"), new byte[10000]);
    archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).build());
    Path apksArchiveFile = archiveBuilder.writeTo(tmpDir.resolve("bundle.apks"));
    ConfigurationSizes configurationSizes = GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).build().getSizeTotalInternal();
    assertThat(configurationSizes.getMinSizeConfigurationMap().keySet()).containsExactly(SizeConfiguration.getDefaultInstance());
    assertThat(configurationSizes.getMinSizeConfigurationMap().get(SizeConfiguration.getDefaultInstance())).isEqualTo(// base+x86
    2 * compressedApkSize);
    assertThat(configurationSizes.getMaxSizeConfigurationMap().keySet()).containsExactly(SizeConfiguration.getDefaultInstance());
    assertThat(configurationSizes.getMaxSizeConfigurationMap().get(SizeConfiguration.getDefaultInstance())).isGreaterThan(// base+x86_64
    2 * compressedApkSize);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ConfigurationSizes(com.android.tools.build.bundletool.model.ConfigurationSizes) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) Test(org.junit.Test)

Example 50 with Variant

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

the class GetSizeCommandTest method getSizeTotal_withAssetModulesAndDeviceSpec.

@Test
public void getSizeTotal_withAssetModulesAndDeviceSpec() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkAbiTargeting(X86, ImmutableSet.of(X86_64)), ZipPath.create("base-x86.apk"), /* isMasterSplit= */
    false), createApkDescription(apkAbiTargeting(X86_64, ImmutableSet.of(X86)), ZipPath.create("base-x86_64.apk"), /* isMasterSplit= */
    false)));
    AssetSliceSet assetModule = createAssetSliceSet(/* moduleName= */
    "asset1", DeliveryType.INSTALL_TIME, createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("asset1-master.apk")), createApkDescription(apkTextureTargeting(ETC2, ImmutableSet.of(ASTC)), ZipPath.create("asset1-tcf_etc2.apk"), /* isMasterSplit= */
    false), createApkDescription(apkTextureTargeting(ASTC, ImmutableSet.of(ETC2)), ZipPath.create("asset1-tcf_astc.apk"), /* isMasterSplit= */
    false));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).addAssetSliceSet(assetModule).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDimensions(ImmutableSet.of(Dimension.ABI, Dimension.TEXTURE_COMPRESSION_FORMAT, Dimension.SDK)).setDeviceSpec(DeviceSpec.newBuilder().setSdkVersion(25).addSupportedAbis("x86").addGlExtensions("GL_KHR_texture_compression_astc_ldr").build()).build().getSizeTotal(new PrintStream(outputStream));
    assertThat(new String(outputStream.toByteArray(), UTF_8)).isEqualTo("SDK,ABI,TEXTURE_COMPRESSION_FORMAT,MIN,MAX" + CRLF + String.format("%s,%s,%s,%d,%d", "25", "x86", "astc", 4 * compressedApkSize, 4 * compressedApkSize) + CRLF);
}
Also used : Variant(com.android.bundle.Commands.Variant) ApksArchiveHelpers.standaloneVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.standaloneVariant) ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Path(java.nio.file.Path) ZipPath(com.android.tools.build.bundletool.model.ZipPath) PrintStream(java.io.PrintStream) BuildApksResult(com.android.bundle.Commands.BuildApksResult) ApksArchiveHelpers.createAssetSliceSet(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createAssetSliceSet) AssetSliceSet(com.android.bundle.Commands.AssetSliceSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

Variant (com.android.bundle.Commands.Variant)134 Test (org.junit.Test)130 BuildApksResult (com.android.bundle.Commands.BuildApksResult)100 ZipPath (com.android.tools.build.bundletool.model.ZipPath)82 Path (java.nio.file.Path)80 ZipFile (java.util.zip.ZipFile)79 AppBundle (com.android.tools.build.bundletool.model.AppBundle)66 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)66 ApkSet (com.android.bundle.Commands.ApkSet)63 ApkDescription (com.android.bundle.Commands.ApkDescription)60 ApkSetUtils.extractFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractFromApkSetFile)59 File (java.io.File)59 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)56 AssetSliceSet (com.android.bundle.Commands.AssetSliceSet)55 ApkSetUtils.extractTocFromApkSetFile (com.android.tools.build.bundletool.testing.ApkSetUtils.extractTocFromApkSetFile)55 CodeRelatedFile (com.android.bundle.CodeTransparencyOuterClass.CodeRelatedFile)54 ApkSetUtils.parseTocFromFile (com.android.tools.build.bundletool.testing.ApkSetUtils.parseTocFromFile)54 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)54 ImmutableSet (com.google.common.collect.ImmutableSet)54 ApkVerifier (com.android.apksig.ApkVerifier)53