Search in sources :

Example 61 with Variant

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

the class ApkSerializerManager method serializeSdkApkSetContent.

private BuildSdkApksResult serializeSdkApkSetContent(Path outputDirectory, GeneratedApks generatedApks) {
    ImmutableList<Variant> allVariantsWithTargeting = serializeApks(outputDirectory, generatedApks, /* deviceSpec= */
    Optional.empty());
    SdkBundle sdkBundle = (SdkBundle) bundle;
    return BuildSdkApksResult.newBuilder().setPackageName(sdkBundle.getPackageName()).addAllVariant(allVariantsWithTargeting).setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).setVersion(SdkVersionInformation.newBuilder().setVersionCode(sdkBundle.getVersionCode()).setMajor(Long.parseLong(sdkBundle.getMajorVersion())).setPatch(Long.parseLong(sdkBundle.getPatchVersion())).build()).build();
}
Also used : Variant(com.android.bundle.Commands.Variant) SdkBundle(com.android.tools.build.bundletool.model.SdkBundle)

Example 62 with Variant

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

the class ApkSizeUtilsTest method multipleVariants_withUncompressedEntries.

@Test
public void multipleVariants_withUncompressedEntries() throws Exception {
    ZipPath apkOne = ZipPath.create("apk_one.apk");
    ZipPath apkTwo = ZipPath.create("apk_two.apk");
    ImmutableList<Variant> variants = ImmutableList.of(createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(21), ImmutableSet.of(sdkVersionFrom(23))), ApkTargeting.getDefaultInstance(), apkOne), createVariantForSingleSplitApk(variantSdkTargeting(sdkVersionFrom(23), ImmutableSet.of(sdkVersionFrom(21))), ApkTargeting.getDefaultInstance(), apkTwo));
    ZipBuilder archiveBuilder = new ZipBuilder();
    archiveBuilder.addFileWithContent(ZipPath.create(apkOne.toString()), DUMMY_BYTES);
    archiveBuilder.addFileWithContent(ZipPath.create(apkTwo.toString()), DUMMY_BYTES, // APK stored uncompressed in the APKs zip.
    EntryOption.UNCOMPRESSED);
    archiveBuilder.addFileWithProtoContent(ZipPath.create("toc.pb"), BuildApksResult.newBuilder().addAllVariant(variants).build());
    Path apksArchiveFile = archiveBuilder.writeTo(tmpDir.resolve("bundle.apks"));
    ImmutableMap<String, Long> sizeByApkPaths = getVariantCompressedSizeByApkPaths(variants, apksArchiveFile);
    assertThat(sizeByApkPaths.keySet()).containsExactly("apk_one.apk", "apk_two.apk");
    long apkOneSize = sizeByApkPaths.get("apk_one.apk");
    long apkTwoSize = sizeByApkPaths.get("apk_two.apk");
    // Apks should have size at least 20. Gzip Header(10 bytes), deflated data (Min 2 Bytes for
    // empty file), 8 bytes footer.
    assertThat(apkOneSize).isGreaterThan(20L);
    assertThat(apkTwoSize).isGreaterThan(20L);
    assertThat(apkOneSize).isEqualTo(apkTwoSize);
}
Also used : ApksArchiveHelpers.createVariant(com.android.tools.build.bundletool.testing.ApksArchiveHelpers.createVariant) Variant(com.android.bundle.Commands.Variant) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Path(java.nio.file.Path) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) ZipPath(com.android.tools.build.bundletool.model.ZipPath) Test(org.junit.Test)

Example 63 with Variant

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

the class BuildSdkApksManagerTest method sdkManifestMutation_patchVersionNotSet_defaultPatchVersionAdded.

@Test
public void sdkManifestMutation_patchVersionNotSet_defaultPatchVersionAdded() throws Exception {
    SdkBundle sdkBundle = new SdkBundleBuilder().setModule(new BundleModuleBuilder("base").setManifest(androidManifest(PACKAGE_NAME, withSdkLibraryElement("20"))).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.getMetadataValue(SDK_PATCH_VERSION_ATTRIBUTE_NAME)).hasValue(DEFAULT_SDK_PATCH_VERSION);
}
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 64 with Variant

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

the class GetSizeCommandTest method getSizeTotalInternal_withDimensionsAndDeviceSpec.

@Test
public void getSizeTotalInternal_withDimensionsAndDeviceSpec() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), createApkDescription(apkLanguageTargeting("jp"), ZipPath.create("base-jp.apk"), /* isMasterSplit= */
    false), createApkDescription(apkLanguageTargeting("fr"), ZipPath.create("base-fr.apk"), /* isMasterSplit= */
    false), createApkDescription(apkDensityTargeting(HDPI, ImmutableSet.of(LDPI)), ZipPath.create("base-hdpi.apk"), /* isMasterSplit= */
    false), createApkDescription(apkDensityTargeting(LDPI, ImmutableSet.of(HDPI)), ZipPath.create("base-ldpi.apk"), /* isMasterSplit= */
    false), createApkDescription(apkAbiTargeting(ARM64_V8A, ImmutableSet.of(ARMEABI_V7A)), ZipPath.create("base-arm64_v8a.apk"), /* isMasterSplit= */
    false), createApkDescription(apkAbiTargeting(ARMEABI_V7A, ImmutableSet.of(ARM64_V8A)), ZipPath.create("base-armeabi_v7a.apk"), /* isMasterSplit= */
    false)));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ConfigurationSizes configurationSizes = GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDeviceSpec(DeviceSpec.newBuilder().setSdkVersion(21).setScreenDensity(125).addSupportedLocales("jp").build()).setDimensions(ImmutableSet.of(Dimension.SDK, Dimension.ABI, Dimension.LANGUAGE, Dimension.SCREEN_DENSITY)).build().getSizeTotalInternal();
    assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setAbi("armeabi-v7a").setLocale("jp").setScreenDensity("125").setSdkVersion("21").build(), 4 * compressedApkSize, SizeConfiguration.builder().setAbi("arm64-v8a").setLocale("jp").setScreenDensity("125").setSdkVersion("21").build(), 4 * compressedApkSize);
    assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setAbi("armeabi-v7a").setLocale("jp").setScreenDensity("125").setSdkVersion("21").build(), 4 * compressedApkSize, SizeConfiguration.builder().setAbi("arm64-v8a").setLocale("jp").setScreenDensity("125").setSdkVersion("21").build(), 4 * 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 65 with Variant

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

the class GetSizeCommandTest method getSizeTotal_withDeviceTier.

@Test
public void getSizeTotal_withDeviceTier() throws Exception {
    Variant lVariant = createVariant(lPlusVariantTargeting(), createSplitApkSet(/* moduleName= */
    "base", createMasterApkDescription(ApkTargeting.getDefaultInstance(), ZipPath.create("base-master.apk")), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    0, /* alternatives= */
    ImmutableList.of(1))), ZipPath.create("base-tier_0.apk")), splitApkDescription(apkDeviceTierTargeting(deviceTierTargeting(/* value= */
    1, /* alternatives= */
    ImmutableList.of(0))), ZipPath.create("base-tier_1.apk"))));
    BuildApksResult tableOfContentsProto = BuildApksResult.newBuilder().setBundletool(Bundletool.newBuilder().setVersion(BundleToolVersion.getCurrentVersion().toString())).addVariant(lVariant).build();
    Path apksArchiveFile = createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GetSizeCommand.builder().setGetSizeSubCommand(GetSizeSubcommand.TOTAL).setApksArchivePath(apksArchiveFile).setDimensions(ImmutableSet.of(Dimension.DEVICE_TIER, Dimension.SDK)).build().getSizeTotal(new PrintStream(outputStream));
    assertThat(new String(outputStream.toByteArray(), UTF_8).split(CRLF)).asList().containsExactly("SDK,DEVICE_TIER,MIN,MAX", String.format("%s,%s,%d,%d", "21-", "0", 2 * compressedApkSize, 2 * compressedApkSize), String.format("%s,%s,%d,%d", "21-", "1", 2 * compressedApkSize, 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) PrintStream(java.io.PrintStream) BuildApksResult(com.android.bundle.Commands.BuildApksResult) 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