use of com.android.bundle.Targeting.ScreenDensity.DensityAlias in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method allSplitsPresentWithResourceTable.
@Test
public void allSplitsPresentWithResourceTable() throws Exception {
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-mdpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(LDPI_VALUE, "res/drawable-ldpi/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).setManifest(androidManifest("com.test.app")).build();
ImmutableSet<DensityAlias> densities = ImmutableSet.of(DensityAlias.LDPI, DensityAlias.MDPI, DensityAlias.TVDPI, DensityAlias.HDPI, DensityAlias.XHDPI, DensityAlias.XXHDPI, DensityAlias.XXXHDPI);
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
for (ModuleSplit resourceSplit : densitySplits) {
assertThat(resourceSplit.getResourceTable().isPresent()).isTrue();
}
List<ApkTargeting> targeting = densitySplits.stream().map(split -> split.getApkTargeting()).collect(Collectors.toList());
assertThat(targeting).ignoringRepeatedFieldOrder().containsExactly(ApkTargeting.getDefaultInstance(), apkDensityTargeting(DensityAlias.LDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.LDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.MDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.MDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.HDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.HDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.TVDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.TVDPI))));
}
use of com.android.bundle.Targeting.ScreenDensity.DensityAlias in project bundletool by google.
the class ScreenDensityResourcesSplitterTest method picksTheResourceForExactDensity.
@Test
public void picksTheResourceForExactDensity() throws Exception {
ResourceTable table = new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.<Integer, String>builder().put(LDPI_VALUE, "res/drawable-ldpi/image.jpg").put(MDPI_VALUE, "res/drawable-mdpi/image.jpg").put(TVDPI_VALUE, "res/drawable-tvdpi/image.jpg").put(HDPI_VALUE, "res/drawable-hdpi/image.jpg").put(XHDPI_VALUE, "res/drawable-xhdpi/image.jpg").put(XXHDPI_VALUE, "res/drawable-xxhdpi/image.jpg").put(XXXHDPI_VALUE, "res/drawable-xxxhdpi/image.jpg").build()).build();
BundleModule testModule = new BundleModuleBuilder("testModule").addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-mdpi/image.jpg").addFile("res/drawable-tvdpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("res/drawable-xhdpi/image.jpg").addFile("res/drawable-xxhdpi/image.jpg").addFile("res/drawable-xxxhdpi/image.jpg").setResourceTable(table).setManifest(androidManifest("com.test.app")).build();
ImmutableSet<DensityAlias> densities = ImmutableSet.of(DensityAlias.LDPI, DensityAlias.MDPI, DensityAlias.TVDPI, DensityAlias.HDPI, DensityAlias.XHDPI, DensityAlias.XXHDPI, DensityAlias.XXXHDPI);
ImmutableCollection<ModuleSplit> densitySplits = splitter.split(ModuleSplit.forResources(testModule));
assertThat(densitySplits).hasSize(DEFAULT_DENSITY_BUCKETS.size() + 1);
assertThat(densitySplits.stream().map(split -> split.getApkTargeting()).collect(toImmutableSet())).ignoringRepeatedFieldOrder().containsExactly(ApkTargeting.getDefaultInstance(), apkDensityTargeting(DensityAlias.LDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.LDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.MDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.MDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.HDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.HDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.XXXHDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.XXXHDPI))), apkDensityTargeting(ImmutableSet.of(DensityAlias.TVDPI), Sets.difference(densities, ImmutableSet.of(DensityAlias.TVDPI))));
for (ModuleSplit densitySplit : densitySplits) {
assertThat(densitySplit.getResourceTable().isPresent()).isTrue();
ResourceTable splitResourceTable = densitySplit.getResourceTable().get();
// we are not verifying the default split in this test.
if (densitySplit.getApkTargeting().equals(ApkTargeting.getDefaultInstance())) {
continue;
}
assertThat(densitySplit.getApkTargeting().hasScreenDensityTargeting()).isTrue();
switch(densitySplit.getApkTargeting().getScreenDensityTargeting().getValue(0).getDensityAlias()) {
case LDPI:
assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(LDPI);
break;
case MDPI:
assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(MDPI);
break;
case TVDPI:
assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(TVDPI);
break;
case HDPI:
assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(HDPI);
break;
case XHDPI:
assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(XHDPI);
break;
case XXHDPI:
assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(XXHDPI);
break;
case XXXHDPI:
assertThat(splitResourceTable).containsResource("com.test.app:drawable/image").onlyWithConfigs(XXXHDPI);
break;
default:
break;
}
}
}
use of com.android.bundle.Targeting.ScreenDensity.DensityAlias in project bundletool by google.
the class ModuleSplitterTest method testSplittingOnDensityAndLanguage_DensityPreferred.
@Test
public void testSplittingOnDensityAndLanguage_DensityPreferred() throws Exception {
// This tests that we output only one dimension for splits and resources already split on
// density are not split further on language.
// Pure language targeted resources are going to be split on language though.
BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("res/drawable-hdpi/image.jpg").addFile("res/drawable-fr-hdpi/image.jpg").addFile("res/drawable/image.jpg").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-fr-hdpi/image.jpg", mergeConfigs(locale("fr"), HDPI)), fileReference("res/drawable-hdpi/image.jpg", HDPI), fileReference("res/drawable/image.jpg", Configuration.getDefaultInstance()))), type(0x02, "strings", entry(0x01, "welcome_label", value("Hello", Configuration.getDefaultInstance()), value("Bienvenue", locale("fr"))))))).setManifest(androidManifest("com.test.app")).build();
List<ModuleSplit> splits = createAbiDensityAndLanguageSplitter(bundleModule).splitModule();
assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
Map<String, ModuleSplit> splitsBySuffix = Maps.uniqueIndex(splits, ModuleSplit::getSuffix);
// 7 density splits (ldpi, mdpi, tvdpi, hdpi, xhdpi, xxhdpi, xxxhdpi) + 1 language split
// + 1 master split = 9 splits
assertThat(splitsBySuffix.keySet()).containsExactly("ldpi", "mdpi", "tvdpi", "hdpi", "xhdpi", "xxhdpi", "xxxhdpi", "fr", "");
ImmutableSet<DensityAlias> densities = ImmutableSet.of(DensityAlias.LDPI, DensityAlias.MDPI, DensityAlias.TVDPI, DensityAlias.HDPI, DensityAlias.XHDPI, DensityAlias.XXHDPI, DensityAlias.XXXHDPI);
assertThat(splitsBySuffix.get("ldpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.LDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.LDPI)))));
assertThat(splitsBySuffix.get("mdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.MDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.MDPI)))));
assertThat(splitsBySuffix.get("tvdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.TVDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.TVDPI)))));
assertThat(splitsBySuffix.get("hdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.HDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.HDPI)))));
assertThat(splitsBySuffix.get("xhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.XHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XHDPI)))));
assertThat(splitsBySuffix.get("xxhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.XXHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XXHDPI)))));
assertThat(splitsBySuffix.get("xxxhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.XXXHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XXXHDPI)))));
assertThat(splitsBySuffix.get("fr").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("fr")));
assertThat(splitsBySuffix.get("").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(DEFAULT_MASTER_SPLIT_SDK_TARGETING);
}
use of com.android.bundle.Targeting.ScreenDensity.DensityAlias in project bundletool by google.
the class ModuleSplitterTest method testSplittingOnDensityAndLanguage_inSameDirectory.
@Ignore("Re-enable when we support generating multiple dimension targeting splits.")
@Test
public void testSplittingOnDensityAndLanguage_inSameDirectory() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("res/drawable-xhdpi/image.jpg").addFile("res/drawable-hdpi/image.jpg").addFile("res/drawable-fr-hdpi/image.jpg").addFile("res/drawable/image.jpg").setResourceTable(resourceTable(pkg(USER_PACKAGE_OFFSET, "com.test.app", type(0x01, "drawable", entry(0x01, "image", fileReference("res/drawable-xhdpi/image.jpg", XHDPI), fileReference("res/drawable-fr-hdpi/image.jpg", mergeConfigs(locale("fr"), HDPI)), fileReference("res/drawable-hdpi/image.jpg", HDPI), fileReference("res/drawable/image.jpg", Configuration.getDefaultInstance())))))).setManifest(androidManifest("com.test.app")).build();
List<ModuleSplit> splits = createAbiDensityAndLanguageSplitter(bundleModule).splitModule();
assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
Map<String, ModuleSplit> splitsBySuffix = Maps.uniqueIndex(splits, ModuleSplit::getSuffix);
// 7 density splits (ldpi, mdpi, tvdpi, hdpi, xhdpi, xxhdpi, xxxhdpi) x 2 language splits
// (one default, one French) + 1 master split = 15
assertThat(splitsBySuffix.keySet()).containsExactly("ldpi", "fr_ldpi", "mdpi", "fr_mdpi", "tvdpi", "fr_tvdpi", "hdpi", "fr_hdpi", "xhdpi", "fr_xhdpi", "xxhdpi", "fr_xxhdpi", "xxxhdpi", "fr_xxxhdpi", "");
ImmutableSet<DensityAlias> densities = ImmutableSet.of(DensityAlias.LDPI, DensityAlias.MDPI, DensityAlias.TVDPI, DensityAlias.HDPI, DensityAlias.XHDPI, DensityAlias.XXHDPI, DensityAlias.XXXHDPI);
assertThat(splitsBySuffix.get("ldpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.LDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.LDPI)))));
assertThat(splitsBySuffix.get("fr_ldpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("fr"), apkDensityTargeting(DensityAlias.LDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.LDPI)))));
assertThat(splitsBySuffix.get("mdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.MDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.MDPI)))));
assertThat(splitsBySuffix.get("fr_mdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("fr"), apkDensityTargeting(DensityAlias.MDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.MDPI)))));
assertThat(splitsBySuffix.get("tvdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.TVDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.TVDPI)))));
assertThat(splitsBySuffix.get("fr_tvdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("fr"), apkDensityTargeting(DensityAlias.TVDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.TVDPI)))));
assertThat(splitsBySuffix.get("hdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.HDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.HDPI)))));
assertThat(splitsBySuffix.get("fr_hdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("fr"), apkDensityTargeting(DensityAlias.HDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.HDPI)))));
assertThat(splitsBySuffix.get("xhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.XHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XHDPI)))));
assertThat(splitsBySuffix.get("fr_xhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("fr"), apkDensityTargeting(DensityAlias.XHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XHDPI)))));
assertThat(splitsBySuffix.get("xxhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.XXHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XXHDPI)))));
assertThat(splitsBySuffix.get("fr_xxhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("fr"), apkDensityTargeting(DensityAlias.XXHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XXHDPI)))));
assertThat(splitsBySuffix.get("xxxhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkDensityTargeting(DensityAlias.XXXHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XXXHDPI)))));
assertThat(splitsBySuffix.get("fr_xxxhdpi").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(mergeApkTargeting(DEFAULT_MASTER_SPLIT_SDK_TARGETING, apkLanguageTargeting("fr"), apkDensityTargeting(DensityAlias.XXXHDPI, Sets.difference(densities, ImmutableSet.of(DensityAlias.XXXHDPI)))));
assertThat(splitsBySuffix.get("").getApkTargeting()).ignoringRepeatedFieldOrder().isEqualTo(DEFAULT_MASTER_SPLIT_SDK_TARGETING);
}
Aggregations