use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_appTargetingPreL_buildsStandaloneApksOnly.
@Test
public void buildApksCommand_appTargetingPreL_buildsStandaloneApksOnly() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.app", withMaxSdkVersion(20)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
// Should not throw.
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getVariantList()).hasSize(1);
assertThat(splitApkVariants(result)).isEmpty();
assertThat(standaloneApkVariants(result)).hasSize(1);
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_splitApks_targetMinSdkVersion.
@Test
public void buildApksCommand_splitApks_targetMinSdkVersion() 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", withMinSdkVersion(25)))).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 variant = splitApkVariants(result).get(0);
assertThat(variant.hasTargeting()).isTrue();
assertThat(variant.getTargeting().getSdkVersionTargeting().getValueList()).containsExactly(sdkVersionFrom(25));
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method deviceTieredAssets_withDeviceSpec_deviceTierSet.
@Test
public void deviceTieredAssets_withDeviceSpec_deviceTierSet() 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"), deviceTier(1))).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 1 has been created, not for 0
ImmutableList<ApkDescription> deviceTierSplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasDeviceTierTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(deviceTierSplits)).containsExactly("base-tier_1.apk");
// Check the content of the APK
ImmutableMap<DeviceTierTargeting, ApkDescription> deviceTierSplitsByTargeting = Maps.uniqueIndex(deviceTierSplits, apk -> apk.getTargeting().getDeviceTierTargeting());
ApkDescription mediumTierSplit = deviceTierSplitsByTargeting.get(deviceTierTargeting(/* value= */
1, /* alternatives= */
ImmutableList.of(0)));
assertThat(filesInApk(mediumTierSplit, apkSetFile)).contains("assets/images#tier_1/image.jpg");
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method selectsRightModules.
@Test
public void selectsRightModules() 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").setManifest(androidManifestForFeature("com.app", withFusingAttribute(true), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).addModule("not_fused", module -> module.addFile("assets/not_fused.txt").setManifest(androidManifestForFeature("com.app", withFusingAttribute(false), withTitle("@string/test_label", TEST_LABEL_RESOURCE_ID)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
// Split APKs: All modules must be used.
ImmutableSet<String> modulesInSplitApks = splitApkVariants(result).stream().flatMap(variant -> variant.getApkSetList().stream()).map(ApkSet::getModuleMetadata).map(ModuleMetadata::getName).collect(toImmutableSet());
assertThat(modulesInSplitApks).containsExactly("base", "fused", "not_fused");
// Standalone APKs: Only base and modules marked for fusing must be used.
assertThat(standaloneApkVariants(result)).hasSize(1);
ImmutableList<ApkDescription> standaloneApks = apkDescriptions(standaloneApkVariants(result).get(0));
assertThat(standaloneApks).hasSize(1);
assertThat(standaloneApks.get(0).hasStandaloneApkMetadata()).isTrue();
assertThat(standaloneApks.get(0).getStandaloneApkMetadata().getFusedModuleNameList()).containsExactly("base", "fused");
File standaloneApkFile = extractFromApkSetFile(apkSetFile, standaloneApks.get(0).getPath(), outputDir);
// Validate that the standalone APK contains appropriate files.
ZipFile standaloneApkZip = openZipFile(standaloneApkFile);
assertThat(filesUnderPath(standaloneApkZip, ZipPath.create("assets"))).containsExactly("assets/base.txt", "assets/fused.txt");
}
use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.
the class BuildApksManagerTest method buildApksCommand_maxSdkVersion_createsExtraAlternative.
@Test
public void buildApksCommand_maxSdkVersion_createsExtraAlternative() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.app", withMinSdkVersion(21), withMaxSdkVersion(25)))).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
assertThat(result.getVariantList()).hasSize(1);
assertThat(standaloneApkVariants(result)).isEmpty();
assertThat(splitApkVariants(result)).hasSize(1);
assertThat(splitApkVariants(result).get(0).getTargeting()).isEqualTo(variantSdkTargeting(/* minSdkVersion= */
21, ImmutableSet.of(26)));
}
Aggregations