use of com.android.tools.build.bundletool.model.AndroidManifest 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.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method mergeInstallTimeDisabled.
@Test
public void mergeInstallTimeDisabled() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app"))).addModule("abi_feature", 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", withInstallTimeDelivery(), withFusingAttribute(true), withInstallTimeRemovableElement(true)))).setBundleConfig(BundleConfigBuilder.create().setVersion("1.0.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);
assertThat(splitApkVariants).isNotEmpty();
assertThat(result.getPermanentlyFusedModulesList()).isEmpty();
for (Variant splitApkVariant : splitApkVariants(result)) {
assertThat(splitApkVariant.getApkSetList()).comparingElementsUsing(Correspondence.from((ApkSet apkSet, String moduleName) -> apkSet != null && apkSet.getModuleMetadata().getName().equals(moduleName), "equals")).containsExactly("base", "abi_feature");
}
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_standalone_oneModuleOneVariant.
@Test
public void buildApksCommand_standalone_oneModuleOneVariant() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.addFile("dex/classes.dex").setManifest(androidManifest("com.test.app"))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(standaloneApkVariants(result)).hasSize(1);
Variant standaloneApkVariant = standaloneApkVariants(result).get(0);
assertThat(standaloneApkVariant.getApkSetList()).hasSize(1);
ApkSet shards = standaloneApkVariant.getApkSet(0);
assertThat(shards.getModuleMetadata().getName()).isEqualTo("base");
assertThat(shards.getApkDescriptionList()).hasSize(1);
assertThat(ZipPath.create(shards.getApkDescription(0).getPath()).getFileName()).isEqualTo(ZipPath.create("standalone.apk"));
assertThat(apkSetFile).hasFile(shards.getApkDescription(0).getPath());
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_universal_mergeApplicationElementsFromFeatureManifest.
@Test
public void buildApksCommand_universal_mergeApplicationElementsFromFeatureManifest() throws Exception {
final int baseThemeRefId = 123;
final int featureThemeRefId = 4456;
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.test.app", withCustomThemeActivity("activity1", baseThemeRefId), withCustomThemeActivity("activity2", baseThemeRefId))).setResourceTable(resourceTableWithTestLabel("Test feature"))).addModule("feature", builder -> builder.setManifest(androidManifestForFeature("com.test.app.feature1", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withCustomThemeActivity("activity1", featureThemeRefId), withSplitNameService("service1", "feature")))).addModule("not_fused", builder -> builder.setManifest(androidManifestForFeature("com.test.app.feature2", withFusingAttribute(false), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID), withCustomThemeActivity("activity2", featureThemeRefId), withSplitNameService("service2", "not_fused")))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withApkBuildMode(UNIVERSAL).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
Variant universalVariant = standaloneApkVariants(result).get(0);
assertThat(apkDescriptions(universalVariant)).hasSize(1);
ApkDescription universalApk = apkDescriptions(universalVariant).get(0);
// Correct modules selected for merging.
assertThat(universalApk.getStandaloneApkMetadata().getFusedModuleNameList()).containsExactly("base", "feature");
File universalApkFile = extractFromApkSetFile(apkSetFile, universalApk.getPath(), outputDir);
AndroidManifest manifest = extractAndroidManifest(universalApkFile, tmpDir);
Map<String, Integer> refIdByActivity = transformValues(manifest.getActivitiesByName(), activity -> activity.getAndroidAttribute(AndroidManifest.THEME_RESOURCE_ID).get().getValueAsRefId());
assertThat(refIdByActivity).containsExactly("activity1", featureThemeRefId, "activity2", baseThemeRefId);
assertThat(getServicesFromManifest(manifest)).containsExactly("service1");
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class AndroidManifestValidator method validateMinMaxSdk.
private static void validateMinMaxSdk(BundleModule module) {
AndroidManifest manifest = module.getAndroidManifest();
Optional<Integer> maxSdk = manifest.getMaxSdkVersion();
Optional<Integer> minSdk = manifest.getMinSdkVersion();
maxSdk.filter(sdk -> sdk < 0).ifPresent(sdk -> {
throw InvalidBundleException.builder().withUserMessage("maxSdkVersion must be nonnegative, found: (%d).", sdk).build();
});
minSdk.filter(sdk -> sdk < 0).ifPresent(sdk -> {
throw InvalidBundleException.builder().withUserMessage("minSdkVersion must be nonnegative, found: (%d).", sdk).build();
});
if (maxSdk.isPresent() && minSdk.isPresent() && maxSdk.get() < minSdk.get()) {
throw InvalidBundleException.builder().withUserMessage("minSdkVersion (%d) is greater than maxSdkVersion (%d).", minSdk.get(), maxSdk.get()).build();
}
}
Aggregations