use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_splitApks_twoModulesOneOnDemand.
@Test
public void buildApksCommand_splitApks_twoModulesOneOnDemand() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("onDemand", builder -> builder.setManifest(androidManifest("com.test.app", withOnDemandAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withFusingAttribute(true)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(splitApkVariants(result)).hasSize(1);
Variant splitApkVariant = splitApkVariants(result).get(0);
ImmutableMap<String, ApkSet> splitApkSetByModuleName = Maps.uniqueIndex(splitApkVariant.getApkSetList(), apkSet -> apkSet.getModuleMetadata().getName());
assertThat(splitApkSetByModuleName).hasSize(2);
ApkSet baseSplits = splitApkSetByModuleName.get("base");
assertThat(baseSplits.getModuleMetadata().getName()).isEqualTo("base");
assertThat(baseSplits.getModuleMetadata().getDeliveryType()).isEqualTo(DeliveryType.INSTALL_TIME);
assertThat(baseSplits.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(baseSplits.getApkDescription(0).getPath());
ApkSet onDemandSplits = splitApkSetByModuleName.get("onDemand");
assertThat(onDemandSplits.getModuleMetadata().getName()).isEqualTo("onDemand");
assertThat(onDemandSplits.getModuleMetadata().getDeliveryType()).isEqualTo(DeliveryType.ON_DEMAND);
assertThat(onDemandSplits.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(onDemandSplits.getApkDescription(0).getPath());
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method defaultUncompressedLibraries_before_0_6_0_disabled_singleVariant.
@Test
public void defaultUncompressedLibraries_before_0_6_0_disabled_singleVariant() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("lib/x86/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)))).setManifest(androidManifest("com.test.app"))).setBundleConfig(BundleConfigBuilder.create().setVersion("0.5.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);
assertThat(splitApkVariants).hasSize(1);
assertThat(splitApkVariants.get(0).getTargeting().getSdkVersionTargeting()).isEqualTo(sdkVersionTargeting(L_SDK_VERSION, ImmutableSet.of(LOWEST_SDK_VERSION)));
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method deviceTieredAssets_withDeviceSpec_deviceTierNotSet_defaultIsUsed.
@Test
public void deviceTieredAssets_withDeviceSpec_deviceTierNotSet_defaultIsUsed() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("assets/images#tier_0/image.jpg").addFile("assets/images#tier_1/image.jpg").setManifest(androidManifest("com.test.app")).setAssetsConfig(assets(targetedAssetsDirectory("assets/images#tier_0", assetsDirectoryTargeting(deviceTierTargeting(/* value= */
0, /* alternatives= */
ImmutableList.of(1)))), targetedAssetsDirectory("assets/images#tier_1", assetsDirectoryTargeting(deviceTierTargeting(/* value= */
1, /* alternatives= */
ImmutableList.of(0))))))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.DEVICE_TIER, /* negate= */
false, /* stripSuffix= */
false, /* defaultSuffix= */
"0").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withDeviceSpec(mergeSpecs(sdkVersion(29), abis("x86"), density(DensityAlias.MDPI), locales("en-US"))).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
ImmutableList<ApkDescription> splitApks = apkDescriptions(splitApkVariants);
// Check that only an APK for tier 0 has been created, not for 1
ImmutableList<ApkDescription> deviceTierSplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasDeviceTierTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(deviceTierSplits)).containsExactly("base-tier_0.apk");
// Check the content of the APK
ImmutableMap<DeviceTierTargeting, ApkDescription> deviceTierSplitsByTargeting = Maps.uniqueIndex(deviceTierSplits, apk -> apk.getTargeting().getDeviceTierTargeting());
ApkDescription lowTierSplit = deviceTierSplitsByTargeting.get(deviceTierTargeting(/* value= */
0, /* alternatives= */
ImmutableList.of(1)));
assertThat(filesInApk(lowTierSplit, apkSetFile)).contains("assets/images#tier_0/image.jpg");
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_generatesSingleApkWithSuffixStrippedTcfAssets.
@Test
public void buildApksCommand_universal_generatesSingleApkWithSuffixStrippedTcfAssets() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app"))).addModule("tcf_assets", builder -> builder.addFile("assets/textures#tcf_atc/atc_texture.dat").addFile("assets/textures#tcf_etc1/etc1_texture.dat").setAssetsConfig(assets(targetedAssetsDirectory("assets/textures#tcf_atc", assetsDirectoryTargeting(textureCompressionTargeting(ATC))), targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery()))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.TEXTURE_COMPRESSION_FORMAT, /* negate= */
false, /* stripSuffix= */
true, /* defaultSuffix= */
"etc1").build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Only assets from "tcf_assets" which are etc1 should be included,
// and the targeting suffix stripped.
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
assertThat(filesUnderPath(universalApkZipFile, ASSETS_DIRECTORY)).containsExactly("assets/textures/etc1_texture.dat");
}
// Check that targeting was applied to both the APK and the variant
assertThat(universalVariant.getTargeting().getTextureCompressionFormatTargeting().getValueList()).containsExactly(textureCompressionFormat(ETC1_RGB8));
assertThat(universalApk.getTargeting().getTextureCompressionFormatTargeting().getValueList()).containsExactly(textureCompressionFormat(ETC1_RGB8));
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_system_withoutLanguageTargeting.
@Test
@Theory
public void buildApksCommand_system_withoutLanguageTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").addFile("lib/mips/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)))).setManifest(androidManifest("com.test.app"))).setBundleConfig(BundleConfigBuilder.create().addSplitDimension(Value.ABI).addSplitDimension(Value.SCREEN_DENSITY, /* negate= */
true).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(SYSTEM).withDeviceSpec(mergeSpecs(sdkVersion(28), abis("mips"), density(DensityAlias.MDPI), locales("en-US"))).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).isEmpty();
assertThat(systemApkVariants(result)).hasSize(1);
Variant systemVariant = systemApkVariants(result).get(0);
assertThat(systemVariant.getTargeting()).isEqualTo(mergeVariantTargeting(variantAbiTargeting(MIPS, ImmutableSet.of(X86, X86_64)), variantSdkTargeting(LOWEST_SDK_VERSION)));
assertThat(apkDescriptions(systemVariant)).hasSize(1);
assertThat(systemVariant.getApkSetList()).hasSize(1);
ApkSet apkSet = systemVariant.getApkSet(0);
apkSet.getApkDescriptionList().forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
}
Aggregations