use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method enableNativeLibraryCompressionWithExternalStorage_multipleSplitVariants.
@Test
public void enableNativeLibraryCompressionWithExternalStorage_multipleSplitVariants() 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", withInstallLocation("auto")))).setBundleConfig(BundleConfigBuilder.create().setUncompressNativeLibraries(true).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.stream().map(variant -> variant.getTargeting().getSdkVersionTargeting())).containsExactly(sdkVersionTargeting(L_SDK_VERSION, ImmutableSet.of(LOWEST_SDK_VERSION, P_SDK_VERSION)), sdkVersionTargeting(P_SDK_VERSION, ImmutableSet.of(LOWEST_SDK_VERSION, L_SDK_VERSION)));
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_strip64BitLibraries_doesNotStrip.
@Test
public void buildApksCommand_universal_strip64BitLibraries_doesNotStrip() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setManifest(androidManifest("com.test.app"))).setBundleConfig(BundleConfig.newBuilder().setOptimizations(Optimizations.newBuilder().setStandaloneConfig(StandaloneConfig.newBuilder().setStrip64BitLibraries(true)).build()).setBundletool(Bundletool.newBuilder().setVersion("0.11.0")).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);
// Should not shard by any dimension and generate single APK with default targeting.
assertThat(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(universalVariant.getTargeting()).isEqualTo(UNRESTRICTED_VARIANT_TARGETING);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
assertThat(universalApk.getTargeting()).isEqualToDefaultInstance();
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
try (ZipFile universalApkZipFile = new ZipFile(universalApkFile)) {
assertThat(filesUnderPath(universalApkZipFile, ZipPath.create("lib"))).containsExactly("lib/x86/libsome.so", "lib/x86_64/libsome.so");
}
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_featureAndAssetModules_generatesAssetSlices.
@Test
@Theory
public void buildApksCommand_featureAndAssetModules_generatesAssetSlices(@FromDataPoints("bundleVersion") Version bundleVersion) throws Exception {
AppBundle appBundle = createAppBundleBuilder(bundleVersion).addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app", withMinSdkVersion(15), withMaxSdkVersion(27), withInstant(true))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("asset_module1", builder -> builder.setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery())).addFile("assets/images/image.jpg")).addModule("asset_module2", builder -> builder.setManifest(androidManifestForAssetModule("com.test.app", withOnDemandDelivery(), withInstantOnDemandDelivery())).addFile("assets/images/image2.jpg")).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Variants
ImmutableList<Variant> variants = splitApkVariants(result);
assertThat(variants).hasSize(1);
Variant splitApkVariant = variants.get(0);
List<ApkSet> apks = splitApkVariant.getApkSetList();
assertThat(apks).hasSize(1);
ApkSet baseSplits = apks.get(0);
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());
// Asset Slices
List<AssetSliceSet> sliceSets = result.getAssetSliceSetList();
assertThat(sliceSets).hasSize(2);
for (AssetSliceSet slice : sliceSets) {
assertThat(slice.getAssetModuleMetadata().hasInstantMetadata()).isTrue();
assertThat(slice.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(slice.getApkDescription(0).getPath());
ApkDescription apkDescription = slice.getApkDescription(0);
assertThat(apkDescription.getPath()).isEqualTo(String.format("asset-slices/%s-master.apk", slice.getAssetModuleMetadata().getName()));
assertThat(apkDescription.hasAssetSliceMetadata()).isTrue();
assertThat(apkDescription.getAssetSliceMetadata().getIsMasterSplit()).isTrue();
}
ImmutableMap<String, AssetSliceSet> sliceSetsByName = Maps.uniqueIndex(sliceSets, set -> set.getAssetModuleMetadata().getName());
assertThat(sliceSetsByName.get("asset_module1").getAssetModuleMetadata().getInstantMetadata().getIsInstant()).isFalse();
assertThat(sliceSetsByName.get("asset_module1").getApkDescription(0).getTargeting()).isEqualTo(ApkTargeting.newBuilder().setSdkVersionTargeting(SdkVersionTargeting.newBuilder().addValue(SdkVersion.newBuilder().setMin(Int32Value.newBuilder().setValue(ANDROID_L_API_VERSION)))).build());
assertThat(sliceSetsByName.get("asset_module2").getApkDescription(0).getTargeting()).isEqualToDefaultInstance();
InstantMetadata.Builder instantMetadata = InstantMetadata.newBuilder().setIsInstant(true);
instantMetadata.setDeliveryType(DeliveryType.ON_DEMAND);
assertThat(sliceSetsByName.get("asset_module2").getAssetModuleMetadata().getInstantMetadata()).isEqualTo(instantMetadata.build());
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_oneModuleManyVariants.
@Test
public void buildApksCommand_standalone_oneModuleManyVariants() 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"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withOptimizationDimensions(ABI).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<Abi, Variant> standaloneVariantsByAbi = Maps.uniqueIndex(standaloneApkVariants(result), variant -> {
ApkDescription apkDescription = getOnlyElement(apkDescriptions(variant));
return getOnlyElement(apkDescription.getTargeting().getAbiTargeting().getValueList());
});
assertThat(standaloneVariantsByAbi.keySet()).containsExactly(toAbi(X86), toAbi(X86_64), toAbi(MIPS));
assertThat(standaloneVariantsByAbi.get(toAbi(X86)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(X86_64, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
assertThat(standaloneVariantsByAbi.get(toAbi(X86_64)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86_64, ImmutableSet.of(X86, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
assertThat(standaloneVariantsByAbi.get(toAbi(MIPS)).getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(MIPS, ImmutableSet.of(X86, X86_64)), variantSdkTargeting(LOWEST_SDK_VERSION, ImmutableSet.of(L_SDK_VERSION, M_SDK_VERSION))));
for (Variant variant : standaloneVariantsByAbi.values()) {
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(apkSet.getApkDescription(0).getPath());
}
}
use of com.android.bundle.Commands.Variant in project bundletool by google.
the class BuildApksManagerTest method explicitMdpiPreferredOverDefault_enabledSince_0_9_1.
@Test
@Theory
public void explicitMdpiPreferredOverDefault_enabledSince_0_9_1(@FromDataPoints("bundleFeatureEnabled") boolean bundleFeatureEnabled) throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("res/drawable/image.jpg").addFile("res/drawable-mdpi/image.jpg").setManifest(androidManifest("com.test.app")).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(/* default */
0, "res/drawable/image.jpg", /* mdpi */
160, "res/drawable-mdpi/image.jpg")).build())).setBundleConfig(BundleConfigBuilder.create().setVersion(bundleFeatureEnabled ? "0.9.1" : "0.9.0").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> mdpiSplits = apkDescriptions(splitApkVariants).stream().filter(apkDesc -> {
List<ScreenDensity> targetDensities = apkDesc.getTargeting().getScreenDensityTargeting().getValueList();
return targetDensities.stream().anyMatch(density -> density.getDensityAlias() == DensityAlias.MDPI) || targetDensities.stream().anyMatch(density -> density.getDensityDpi() == MDPI_VALUE);
}).collect(toImmutableList());
String fileToBePresent;
String fileToBeAbsent;
if (bundleFeatureEnabled) {
fileToBePresent = "res/drawable-mdpi/image.jpg";
fileToBeAbsent = "res/drawable/image.jpg";
} else {
fileToBeAbsent = "res/drawable-mdpi/image.jpg";
fileToBePresent = "res/drawable/image.jpg";
}
assertThat(mdpiSplits).isNotEmpty();
for (ApkDescription mdpiSplit : mdpiSplits) {
assertThat(filesInApk(mdpiSplit, apkSetFile)).contains(fileToBePresent);
assertThat(filesInApk(mdpiSplit, apkSetFile)).doesNotContain(fileToBeAbsent);
}
}
Aggregations