use of com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM in project bundletool by google.
the class BuildApksManagerTest method multipleModulesFusedAndNotFused_systemApks_hasCorrectAdditionalLanguageSplits.
@Test
@Theory
public void multipleModulesFusedAndNotFused_systemApks_hasCorrectAdditionalLanguageSplits() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("assets/base.txt").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)))).addModule("notfused", module -> module.addFile("assets/notfused.txt").addFile("assets/notfused/languages#lang_it/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/notfused/languages#lang_it", assetsDirectoryTargeting(languageTargeting("it"))))).setManifest(androidManifestForFeature("com.app", withFusingAttribute(false), 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(2);
ImmutableMap<String, ApkSet> apkSetByModule = Maps.uniqueIndex(systemVariant.getApkSetList(), apkSet -> apkSet.getModuleMetadata().getName());
assertThat(apkSetByModule.keySet()).containsExactly("base", "notfused");
ApkSet baseApkSet = apkSetByModule.get("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()));
ApkSet nonFusedApkSet = apkSetByModule.get("notfused");
assertThat(nonFusedApkSet.getApkDescriptionList()).hasSize(2);
assertThat(nonFusedApkSet.getApkDescriptionList().stream().map(ApkDescription::getPath).collect(toImmutableSet())).containsExactly("splits/notfused-master.apk", "splits/notfused-it.apk");
nonFusedApkSet.getApkDescriptionList().forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
}
use of com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM in project bundletool by google.
the class BuildApksDeviceSpecTest method deviceSpec_systemApkMode_withoutDeviceSpec_throws.
@Test
@Theory
public void deviceSpec_systemApkMode_withoutDeviceSpec_throws() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app"))).build();
bundleSerializer.writeToDisk(appBundle, bundlePath);
BuildApksCommand.Builder command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setApkBuildMode(SYSTEM);
Throwable exception = assertThrows(InvalidCommandException.class, command::build);
assertThat(exception).hasMessageThat().contains("Device spec must always be set when running with 'system' mode flag.");
}
use of com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM in project bundletool by google.
the class BuildApksDeviceSpecTest method deviceSpec_systemApkMode_partialDeviceSpecMissingDensity_throws.
@Test
@Theory
public void deviceSpec_systemApkMode_partialDeviceSpecMissingDensity_throws() throws Exception {
DeviceSpec deviceSpec = mergeSpecs(abis("arm64-v8a"));
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app"))).build();
bundleSerializer.writeToDisk(appBundle, bundlePath);
BuildApksCommand.Builder command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpec).setApkBuildMode(SYSTEM);
Throwable exception = assertThrows(InvalidCommandException.class, command::build);
assertThat(exception).hasMessageThat().contains("Device spec must have screen density and ABIs set when running with 'system' mode" + " flag.");
}
use of com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM in project bundletool by google.
the class BuildApksDeviceSpecTest method deviceSpec_systemApkMode_partialDeviceSpecMissingAbi_throws.
@Test
@Theory
public void deviceSpec_systemApkMode_partialDeviceSpecMissingAbi_throws() throws Exception {
DeviceSpec deviceSpec = mergeSpecs(density(DensityAlias.MDPI));
AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.setManifest(androidManifest("com.app"))).build();
bundleSerializer.writeToDisk(appBundle, bundlePath);
BuildApksCommand.Builder command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).setDeviceSpec(deviceSpec).setApkBuildMode(SYSTEM);
Throwable exception = assertThrows(InvalidCommandException.class, command::build);
assertThat(exception).hasMessageThat().contains("Device spec must have screen density and ABIs set when running with 'system' mode" + " flag.");
}
use of com.android.tools.build.bundletool.commands.BuildApksCommand.ApkBuildMode.SYSTEM in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_system_withLanguageTargeting.
@Test
@Theory
public void buildApksCommand_system_withLanguageTargeting() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").addFile("lib/mips/libsome.so").addFile("assets/languages#lang_es/image.jpg").addFile("assets/languages#lang_fr/image.jpg").addFile("assets/languages#lang_it/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addStringResource("title", "Not fused").build()).setAssetsConfig(assets(targetedAssetsDirectory("assets/languages#lang_it", assetsDirectoryTargeting(languageTargeting("it"))), targetedAssetsDirectory("assets/languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)))).setManifest(androidManifest("com.test.app"))).addModule("not_fused", builder -> builder.addFile("lib/x86/libother.so").addFile("lib/x86_64/libother.so").addFile("lib/mips/libother.so").addFile("assets/other_languages#lang_es/image.jpg").addFile("assets/other_languages#lang_fr/image.jpg").addFile("assets/other_languages#lang_it/image.jpg").setAssetsConfig(assets(targetedAssetsDirectory("assets/other_languages#lang_it", assetsDirectoryTargeting(languageTargeting("it"))), targetedAssetsDirectory("assets/other_languages#lang_es", assetsDirectoryTargeting(languageTargeting("es"))), targetedAssetsDirectory("assets/other_languages#lang_fr", assetsDirectoryTargeting(languageTargeting("fr"))))).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)), targetedNativeDirectory("lib/mips", nativeDirectoryTargeting(MIPS)))).setManifest(androidManifestForFeature("com.test.app", withTitle("Not fused", 0x7f010000), withFusingAttribute(false)))).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(result.getVariantList()).hasSize(1);
Variant x86Variant = result.getVariant(0);
assertThat(x86Variant.getVariantNumber()).isEqualTo(0);
assertThat(x86Variant.getTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(X86_64, MIPS)), variantSdkTargeting(LOWEST_SDK_VERSION)));
assertThat(x86Variant.getApkSetList()).hasSize(2);
ApkSet apkSet = x86Variant.getApkSet(0);
assertThat(apkSet.getApkDescriptionList().stream().map(ApkDescription::getPath).collect(toImmutableSet())).containsExactly("system/system.apk", "splits/base-it.apk", "splits/base-fr.apk");
ApkSet apkSetNotFusedModule = x86Variant.getApkSet(1);
assertThat(apkSetNotFusedModule.getApkDescriptionList().stream().map(ApkDescription::getPath).collect(toImmutableSet())).containsExactly("splits/not_fused-master.apk", "splits/not_fused-es.apk", "splits/not_fused-it.apk", "splits/not_fused-fr.apk", "splits/not_fused-x86.apk");
apkSet.getApkDescriptionList().forEach(apkDescription -> assertThat(apkSetFile).hasFile(apkDescription.getPath()));
}
Aggregations