use of com.android.bundle.Targeting.DeviceTierTargeting in project bundletool by google.
the class AbstractSizeAggregator method getSizesPerConfiguration.
protected ConfigurationSizes getSizesPerConfiguration(ImmutableSet<SdkVersionTargeting> sdkTargetingOptions, ImmutableSet<AbiTargeting> abiTargetingOptions, ImmutableSet<LanguageTargeting> languageTargetingOptions, ImmutableSet<ScreenDensityTargeting> screenDensityTargetingOptions, ImmutableSet<TextureCompressionFormatTargeting> textureCompressionFormatTargetingOptions, ImmutableSet<DeviceTierTargeting> deviceTierTargetingOptions) {
Map<SizeConfiguration, Long> minSizeByConfiguration = new HashMap<>();
Map<SizeConfiguration, Long> maxSizeByConfiguration = new HashMap<>();
for (SdkVersionTargeting sdkVersionTargeting : sdkTargetingOptions) {
for (AbiTargeting abiTargeting : abiTargetingOptions) {
for (ScreenDensityTargeting screenDensityTargeting : screenDensityTargetingOptions) {
for (LanguageTargeting languageTargeting : languageTargetingOptions) {
for (TextureCompressionFormatTargeting textureCompressionFormatTargeting : textureCompressionFormatTargetingOptions) {
for (DeviceTierTargeting deviceTierTargeting : deviceTierTargetingOptions) {
SizeConfiguration configuration = mergeWithDeviceSpec(getSizeConfiguration(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting), getSizeRequest.getDeviceSpec());
long compressedSize = getCompressedSize(getMatchingApks(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting));
minSizeByConfiguration.merge(configuration, compressedSize, Math::min);
maxSizeByConfiguration.merge(configuration, compressedSize, Math::max);
}
}
}
}
}
}
return ConfigurationSizes.create(/* minSizeConfigurationMap= */
ImmutableMap.copyOf(minSizeByConfiguration), /* maxSizeConfigurationMap= */
ImmutableMap.copyOf(maxSizeByConfiguration));
}
use of com.android.bundle.Targeting.DeviceTierTargeting 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());
}
Aggregations