use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksManagerTest method multipleModules_systemApks_hasCorrectAdditionalLanguageSplits.
@Test
@Theory
public void multipleModules_systemApks_hasCorrectAdditionalLanguageSplits() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("assets/base.txt").addFile("assets/languages#lang_es/image.jpg").addFile("assets/languages#lang_fr/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifest("com.app")).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("fused", module -> module.addFile("assets/fused.txt").addFile("assets/fused/languages#lang_es/image.jpg").addFile("assets/fused/languages#lang_fr/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/fused/languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/fused/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setManifest(androidManifestForFeature("com.app", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(SYSTEM).withDeviceSpec(mergeSpecs(sdkVersion(28), abis("x86"), density(DensityAlias.MDPI), locales("es"))).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(systemApkVariants(result)).hasSize(1);
Variant systemVariant = result.getVariant(0);
assertThat(systemVariant.getVariantNumber()).isEqualTo(0);
assertThat(systemVariant.getApkSetList()).hasSize(1);
ApkSet baseApkSet = Iterables.getOnlyElement(systemVariant.getApkSetList());
assertThat(baseApkSet.getModuleMetadata().getName()).isEqualTo("base");
assertThat(baseApkSet.getApkDescriptionList()).hasSize(2);
assertThat(baseApkSet.getApkDescriptionList().stream().map(ApkDescription::getPath).collect(toImmutableSet())).containsExactly("system/system.apk", "splits/base-fr.apk");
baseApkSet.getApkDescriptionList().forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
}
use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_apkNotificationMessageKeyApexBundle.
@Test
public void buildApksCommand_apkNotificationMessageKeyApexBundle() throws Exception {
ApexImages apexConfig = apexImages(targetedApexImage("apex/x86_64.x86.img", apexImageTargeting("x86_64", "x86")), targetedApexImage("apex/x86_64.armeabi-v7a.img", apexImageTargeting("x86_64", "armeabi-v7a")), targetedApexImage("apex/x86_64.img", apexImageTargeting("x86_64")), targetedApexImage("apex/x86.armeabi-v7a.img", apexImageTargeting("x86", "armeabi-v7a")), targetedApexImage("apex/x86.img", apexImageTargeting("x86")), targetedApexImage("apex/arm64-v8a.img", apexImageTargeting("arm64-v8a")), targetedApexImage("apex/armeabi-v7a.img", apexImageTargeting("armeabi-v7a")));
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile(APEX_MANIFEST_PATH, APEX_MANIFEST).addFile("apex/x86_64.x86.img").addFile("apex/x86_64.armeabi-v7a.img").addFile("apex/x86_64.img").addFile("apex/x86.armeabi-v7a.img").addFile("apex/x86.img").addFile("apex/arm64-v8a.img").addFile("apex/armeabi-v7a.img").setApexConfig(apexConfig).setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ImmutableSet<AbiAlias> x64X86Set = ImmutableSet.of(X86, X86_64);
ImmutableSet<AbiAlias> x64ArmSet = ImmutableSet.of(ARMEABI_V7A, X86_64);
ImmutableSet<AbiAlias> x64Set = ImmutableSet.of(X86_64);
ImmutableSet<AbiAlias> x86ArmSet = ImmutableSet.of(ARMEABI_V7A, X86);
ImmutableSet<AbiAlias> x86Set = ImmutableSet.of(X86);
ImmutableSet<AbiAlias> arm8Set = ImmutableSet.of(ARM64_V8A);
ImmutableSet<AbiAlias> arm7Set = ImmutableSet.of(ARMEABI_V7A);
ImmutableSet<ImmutableSet<AbiAlias>> allTargeting = ImmutableSet.of(arm7Set, x86ArmSet, x64ArmSet, arm8Set, x86Set, x64X86Set, x64Set);
ApkTargeting x64X86Targeting = apkMultiAbiTargetingFromAllTargeting(x64X86Set, allTargeting);
ApkTargeting x64ArmTargeting = apkMultiAbiTargetingFromAllTargeting(x64ArmSet, allTargeting);
ApkTargeting x64Targeting = apkMultiAbiTargetingFromAllTargeting(x64Set, allTargeting);
ApkTargeting x86ArmTargeting = apkMultiAbiTargetingFromAllTargeting(x86ArmSet, allTargeting);
ApkTargeting x86Targeting = apkMultiAbiTargetingFromAllTargeting(x86Set, allTargeting);
ApkTargeting arm8Targeting = apkMultiAbiTargetingFromAllTargeting(arm8Set, allTargeting);
ApkTargeting arm7Targeting = apkMultiAbiTargetingFromAllTargeting(arm7Set, allTargeting);
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableMap<ApkTargeting, Variant> apexVariantsByAbi = extractApexVariantsByTargeting(result);
assertThat(apexVariantsByAbi.keySet()).containsExactly(x64X86Targeting, x64ArmTargeting, x64Targeting, x86ArmTargeting, x86Targeting, arm8Targeting, arm7Targeting);
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x64X86Targeting), variantMultiAbiTargetingFromAllTargeting(x64X86Set, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x64ArmTargeting), variantMultiAbiTargetingFromAllTargeting(x64ArmSet, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x64Targeting), variantMultiAbiTargetingFromAllTargeting(x64Set, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x86ArmTargeting), variantMultiAbiTargetingFromAllTargeting(x86ArmSet, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(x86Targeting), variantMultiAbiTargetingFromAllTargeting(x86Set, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(arm8Targeting), variantMultiAbiTargetingFromAllTargeting(arm8Set, allTargeting));
checkVariantMultiAbiTargeting(apexVariantsByAbi.get(arm7Targeting), variantMultiAbiTargetingFromAllTargeting(arm7Set, allTargeting));
for (Variant variant : apexVariantsByAbi.values()) {
ApkSet apkSet = getOnlyElement(variant.getApkSetList());
ApkDescription apkDescription = getOnlyElement(apkSet.getApkDescriptionList());
assertThat(apkSetFile).hasFile(apkDescription.getPath());
}
}
use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksPreprocessingTest method buildApksCommand_overridesAssetModuleCompression.
@Test
public void buildApksCommand_overridesAssetModuleCompression() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("dex/classes.dex", DUMMY_CONTENT).addFile("assets/images/image.jpg", DUMMY_CONTENT).setManifest(androidManifest("com.test.app", withMinSdkVersion(15), withMaxSdkVersion(27))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("asset_module", module -> module.setManifest(androidManifestForAssetModule("com.test.app", withInstallTimeDelivery())).addFile("assets/textures/texture.etc", DUMMY_CONTENT)).build();
new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
command.execute();
try (ZipFile apkSetFile = new ZipFile(outputFilePath.toFile())) {
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Standalone variant.
ImmutableList<Variant> standaloneVariants = standaloneApkVariants(result);
assertThat(standaloneVariants).hasSize(1);
Variant standaloneVariant = standaloneVariants.get(0);
assertThat(standaloneVariant.getApkSetList()).hasSize(1);
ApkSet standaloneApk = standaloneVariant.getApkSet(0);
assertThat(standaloneApk.getApkDescriptionList()).hasSize(1);
assertThat(apkSetFile).hasFile(standaloneApk.getApkDescription(0).getPath());
File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApk.getApkDescription(0).getPath(), outputDir);
try (ZipFile apkZip = new ZipFile(standaloneApkFile)) {
assertThat(apkZip).hasFile("classes.dex").thatIsCompressed();
assertThat(apkZip).hasFile("assets/images/image.jpg").thatIsCompressed();
assertThat(apkZip).hasFile("assets/textures/texture.etc").thatIsUncompressed();
}
// L+ assets.
assertThat(result.getAssetSliceSetCount()).isEqualTo(1);
AssetSliceSet assetSlice = result.getAssetSliceSet(0);
assertThat(assetSlice.getApkDescriptionCount()).isEqualTo(1);
File apkFile = extractFromApkSetFile(apkSetFile, assetSlice.getApkDescription(0).getPath(), outputDir);
try (ZipFile apkZip = new ZipFile(apkFile)) {
assertThat(apkZip).hasFile("assets/textures/texture.etc").thatIsUncompressed();
}
}
}
use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksDeviceSpecTest method deviceSpec_correctSplitsGenerated.
@Test
public void deviceSpec_correctSplitsGenerated() throws Exception {
DeviceSpec deviceSpec = lDeviceWithDensity(XHDPI);
bundleSerializer.writeToDisk(createLdpiHdpiAppBundle(), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpec).build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "splits/base-master.apk", "splits/base-xhdpi.apk");
result = extractTocFromApkSetFile(apksZipFile, outputDir);
}
assertThat(result.getVariantList()).hasSize(1);
Variant variant = result.getVariant(0);
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
// One master and one density split.
assertThat(apkSet.getApkDescriptionList()).hasSize(2);
assertThat(apkNamesInSet(apkSet)).containsExactly("splits/base-master.apk", "splits/base-xhdpi.apk");
}
use of com.android.bundle.Commands.ApkSet in project bundletool by google.
the class BuildApksDeviceSpecTest method deviceSpec_instantSplitsGenerated.
@Test
public void deviceSpec_instantSplitsGenerated() throws Exception {
DeviceSpec deviceSpec = lDeviceWithDensity(XHDPI);
bundleSerializer.writeToDisk(createInstantBundle(), bundlePath);
BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpec).build();
Path apksArchive = command.execute();
BuildApksResult result;
try (ZipFile apksZipFile = new ZipFile(apksArchive.toFile())) {
assertThat(apksZipFile).containsExactlyEntries("toc.pb", "splits/base-master.apk", "instant/instant-base-master.apk");
result = extractTocFromApkSetFile(apksZipFile, outputDir);
}
assertThat(instantApkVariants(result)).hasSize(1);
assertThat(splitApkVariants(result)).hasSize(1);
Variant variant = splitApkVariants(result).get(0);
assertThat(variant.getApkSetList()).hasSize(1);
ApkSet apkSet = variant.getApkSet(0);
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkNamesInSet(apkSet)).containsExactly("splits/base-master.apk");
variant = instantApkVariants(result).get(0);
assertThat(variant.getApkSetList()).hasSize(1);
apkSet = variant.getApkSet(0);
assertThat(apkSet.getApkDescriptionList()).hasSize(1);
assertThat(apkNamesInSet(apkSet)).containsExactly("instant/instant-base-master.apk");
}
Aggregations