use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method deviceTieredAssets_inBaseModule.
@Test
public void deviceTieredAssets_inBaseModule() 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).build());
buildApksManager.execute();
ZipFile apkSetFile = openZipFile(outputFilePath.toFile());
BuildApksResult result = extractTocFromApkSetFile(apkSetFile, outputDir);
ImmutableList<Variant> splitApkVariants = splitApkVariants(result);
ImmutableList<ApkDescription> splitApks = apkDescriptions(splitApkVariants);
assertThat(splitApkVariants(result)).hasSize(1);
Variant splitApkVariant = splitApkVariants(result).get(0);
// Check that apks for tier 0 and 1 have been created
assertThat(splitApkVariant.getApkSetList()).hasSize(1);
ImmutableList<ApkDescription> deviceTierSplits = splitApks.stream().filter(apkDesc -> apkDesc.getTargeting().hasDeviceTierTargeting()).collect(toImmutableList());
assertThat(apkNamesInApkDescriptions(deviceTierSplits)).containsExactly("base-tier_0.apk", "base-tier_1.apk");
// Check the content of the APKs
ImmutableMap<DeviceTierTargeting, ApkDescription> deviceTierSplitsByTargeting = Maps.uniqueIndex(deviceTierSplits, apk -> apk.getTargeting().getDeviceTierTargeting());
ApkDescription lowTierSplit = deviceTierSplitsByTargeting.get(deviceTierTargeting(/* value= */
0, /* alternatives= */
ImmutableList.of(1)));
assertThat(ZipPath.create(lowTierSplit.getPath()).getFileName().toString()).isEqualTo("base-tier_0.apk");
assertThat(filesInApk(lowTierSplit, apkSetFile)).contains("assets/images#tier_0/image.jpg");
ApkDescription mediumTierSplit = deviceTierSplitsByTargeting.get(deviceTierTargeting(/* value= */
1, /* alternatives= */
ImmutableList.of(0)));
assertThat(ZipPath.create(mediumTierSplit.getPath()).getFileName().toString()).isEqualTo("base-tier_1.apk");
assertThat(filesInApk(mediumTierSplit, apkSetFile)).contains("assets/images#tier_1/image.jpg");
assertThat(result.getDefaultTargetingValueList()).containsExactly(DefaultTargetingValue.newBuilder().setDimension(Value.DEVICE_TIER).setDefaultValue("0").build());
}
use of com.android.bundle.Commands.ApkDescription in project bundletool by google.
the class BuildApksManagerTest method allApksSignedWithV1_minSdkLessThan24.
@Test
public void allApksSignedWithV1_minSdkLessThan24() throws Exception {
AppBundle appBundle = new AppBundleBuilder().addModule("base", builder -> builder.setManifest(androidManifest("com.app", withMinSdkVersion(23)))).setBundleConfig(BundleConfig.newBuilder().setBundletool(Bundletool.newBuilder().setVersion("0.11.0")).build()).build();
TestComponent.useTestModule(this, createTestModuleBuilder().withAppBundle(appBundle).withOutputPath(outputFilePath).withSigningConfig(SigningConfiguration.builder().setSignerConfig(privateKey, certificate).build()).build());
buildApksManager.execute();
try (ZipFile apkSet = new ZipFile(outputFilePath.toFile())) {
BuildApksResult result = extractTocFromApkSetFile(apkSet, outputDir);
ImmutableList<ApkDescription> apkDescriptions = apkDescriptions(result.getVariantList());
assertThat(apkDescriptions).isNotEmpty();
for (ApkDescription apkDescription : apkDescriptions) {
ImmutableSet<String> filesInApk = filesInApk(apkDescription, apkSet);
assertThat(filesInApk).contains(String.format("META-INF/%s.RSA", SIGNER_CONFIG_NAME));
}
}
}
Aggregations