use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class AlternativeVariantTargetingPopulatorTest method splitAndStandalones_addsAlternatives.
@Test
public void splitAndStandalones_addsAlternatives() throws Exception {
SdkVersion lPlusVersion = sdkVersionFrom(Versions.ANDROID_L_API_VERSION);
VariantTargeting lPlusTargeting = variantSdkTargeting(lPlusVersion);
VariantTargeting emptySdkTargeting = variantSdkTargeting(SdkVersion.getDefaultInstance());
// Post-L splits with 2 modules.
ImmutableList<ModuleSplit> postLSplits = ImmutableList.of(createModuleSplit(lPlusTargeting), createModuleSplit(lPlusTargeting));
// 3 density shards.
ImmutableList<ModuleSplit> standaloneShards = ImmutableList.of(createStandaloneModuleSplit(mergeVariantTargeting(emptySdkTargeting, variantDensityTargeting(DensityAlias.MDPI))), createStandaloneModuleSplit(mergeVariantTargeting(emptySdkTargeting, variantDensityTargeting(DensityAlias.HDPI))), createStandaloneModuleSplit(mergeVariantTargeting(emptySdkTargeting, variantDensityTargeting(DensityAlias.XHDPI))));
GeneratedApks generatedApks = GeneratedApks.builder().setStandaloneApks(standaloneShards).setSplitApks(postLSplits).build();
GeneratedApks processedApks = AlternativeVariantTargetingPopulator.populateAlternativeVariantTargeting(generatedApks);
assertThat(processedApks.size()).isEqualTo(5);
ImmutableCollection<ModuleSplit> processedShards = processedApks.getStandaloneApks();
assertThat(processedShards).hasSize(3);
assertThat(processedShards.stream().map(ModuleSplit::getVariantTargeting).collect(toImmutableSet())).containsExactly(mergeVariantTargeting(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(lPlusVersion)), variantDensityTargeting(DensityAlias.MDPI, ImmutableSet.of(DensityAlias.HDPI, DensityAlias.XHDPI))), mergeVariantTargeting(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(lPlusVersion)), variantDensityTargeting(DensityAlias.HDPI, ImmutableSet.of(DensityAlias.MDPI, DensityAlias.XHDPI))), mergeVariantTargeting(variantSdkTargeting(SdkVersion.getDefaultInstance(), ImmutableSet.of(lPlusVersion)), variantDensityTargeting(DensityAlias.XHDPI, ImmutableSet.of(DensityAlias.MDPI, DensityAlias.HDPI))));
}
use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class AssetModuleSizeAggregatorTest method getSize_multipleAssetModules_withDeviceSpecAndVariantTargeting.
@Test
public void getSize_multipleAssetModules_withDeviceSpecAndVariantTargeting() throws Exception {
ImmutableList<AssetSliceSet> assetModules = ImmutableList.of(ASSET_MODULE_1, ASSET_MODULE_2);
VariantTargeting variantTargeting = variantTextureTargeting(ETC2);
ConfigurationSizes configurationSizes = new AssetModuleSizeAggregator(assetModules, variantTargeting, SIZE_BY_APK_PATHS, getSizeCommand.setDimensions(ImmutableSet.of(TEXTURE_COMPRESSION_FORMAT, SDK)).setDeviceSpec(sdkVersion(21)).build()).getSize();
assertThat(configurationSizes.getMinSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setTextureCompressionFormat("etc2").setSdkVersion("21").build(), ASSET_1_MASTER_SIZE + ASSET_1_ETC2_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ETC2_SIZE);
assertThat(configurationSizes.getMaxSizeConfigurationMap()).containsExactly(SizeConfiguration.builder().setTextureCompressionFormat("etc2").setSdkVersion("21").build(), ASSET_1_MASTER_SIZE + ASSET_1_ETC2_SIZE + ASSET_2_MASTER_SIZE + ASSET_2_ETC2_SIZE);
}
use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class SameTargetingMerger method mergeSplits.
private ModuleSplit mergeSplits(ImmutableCollection<ModuleSplit> splits) {
ModuleSplit.Builder builder = ModuleSplit.builder();
ImmutableList.Builder<ModuleEntry> entries = ImmutableList.builder();
AndroidManifest mergedManifest = null;
ResourceTable mergedResourceTable = null;
NativeLibraries mergedNativeConfig = null;
Map<String, TargetedAssetsDirectory> mergedAssetsConfig = new HashMap<>();
ApexImages mergedApexConfig = null;
ImmutableList<ApexEmbeddedApkConfig> mergedApexEmbeddedApkConfigs = null;
BundleModuleName mergedModuleName = null;
Boolean mergedIsMasterSplit = null;
VariantTargeting mergedVariantTargeting = null;
for (ModuleSplit split : splits) {
mergedManifest = getSameValueOrNonNull(mergedManifest, split.getAndroidManifest()).orElseThrow(() -> new IllegalStateException("Encountered two distinct manifests while merging."));
if (split.getResourceTable().isPresent()) {
mergedResourceTable = getSameValueOrNonNull(mergedResourceTable, split.getResourceTable().get()).orElseThrow(() -> new IllegalStateException("Unsupported case: encountered two distinct resource tables while " + "merging."));
}
if (split.getNativeConfig().isPresent()) {
mergedNativeConfig = getSameValueOrNonNull(mergedNativeConfig, split.getNativeConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct native configs while merging."));
}
if (split.getApexConfig().isPresent()) {
mergedApexConfig = getSameValueOrNonNull(mergedApexConfig, split.getApexConfig().get()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex configs while merging."));
}
mergedApexEmbeddedApkConfigs = getSameValueOrNonNull(mergedApexEmbeddedApkConfigs, split.getApexEmbeddedApkConfigs()).orElseThrow(() -> new IllegalStateException("Encountered two distinct apex embedded apk configs while merging."));
mergedModuleName = getSameValueOrNonNull(mergedModuleName, split.getModuleName()).orElseThrow(() -> new IllegalStateException("Encountered two distinct module names while merging."));
mergedIsMasterSplit = getSameValueOrNonNull(mergedIsMasterSplit, Boolean.valueOf(split.isMasterSplit())).orElseThrow(() -> new IllegalStateException("Encountered conflicting isMasterSplit flag values while merging."));
mergedVariantTargeting = getSameValueOrNonNull(mergedVariantTargeting, split.getVariantTargeting()).orElseThrow(() -> new IllegalStateException("Encountered conflicting variant targeting values while merging."));
entries.addAll(split.getEntries());
builder.setApkTargeting(split.getApkTargeting());
split.getAssetsConfig().ifPresent(assetsConfig -> {
mergeTargetedAssetsDirectories(mergedAssetsConfig, assetsConfig.getDirectoryList());
});
}
if (mergedManifest != null) {
builder.setAndroidManifest(mergedManifest);
}
if (mergedResourceTable != null) {
builder.setResourceTable(mergedResourceTable);
}
if (mergedNativeConfig != null) {
builder.setNativeConfig(mergedNativeConfig);
}
if (!mergedAssetsConfig.isEmpty()) {
builder.setAssetsConfig(Assets.newBuilder().addAllDirectory(mergedAssetsConfig.values()).build());
}
if (mergedApexConfig != null) {
builder.setApexConfig(mergedApexConfig);
}
if (mergedApexEmbeddedApkConfigs != null) {
builder.setApexEmbeddedApkConfigs(mergedApexEmbeddedApkConfigs);
}
if (mergedModuleName != null) {
builder.setModuleName(mergedModuleName);
}
if (mergedIsMasterSplit != null) {
builder.setMasterSplit(mergedIsMasterSplit);
}
builder.setVariantTargeting(mergedVariantTargeting);
builder.setEntries(entries.build());
return builder.build();
}
use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class TargetingNormalizerTest method normalizeVariantTargeting_allTargetingDimensionsAreHandled.
@Test
public void normalizeVariantTargeting_allTargetingDimensionsAreHandled() {
VariantTargeting variantTargeting = ProtoFuzzer.randomProtoMessage(VariantTargeting.class);
VariantTargeting shuffledVariantTargeting = ProtoFuzzer.shuffleRepeatedFields(variantTargeting);
// Sanity-check that the testing data was generated alright.
assertThat(variantTargeting).isNotEqualTo(shuffledVariantTargeting);
// The following check fails, if the normalizing logic forgets to handle some dimension.
// This would typically happen when the targeting proto is extended by a new dimension.
assertThat(TargetingNormalizer.normalizeVariantTargeting(variantTargeting)).isEqualTo(TargetingNormalizer.normalizeVariantTargeting(shuffledVariantTargeting));
}
use of com.android.bundle.Targeting.VariantTargeting in project bundletool by google.
the class StandaloneApksGeneratorTest method shardByAbi_havingManyAbis_producesManyApks.
@Test
public void shardByAbi_havingManyAbis_producesManyApks() throws Exception {
BundleModule bundleModule = new BundleModuleBuilder("base").addFile("assets/file.txt").addFile("dex/classes.dex").addFile("lib/armeabi/libtest.so").addFile("lib/x86/libtest.so").addFile("lib/x86_64/libtest.so").addFile("res/drawable/image.jpg").addFile("res/drawable-mdpi/image.jpg").addFile("root/license.dat").setManifest(androidManifest("com.test.app")).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi", nativeDirectoryTargeting(ARMEABI)), targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(X86_64)))).setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(DEFAULT_DENSITY_VALUE, "res/drawable/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).build();
ImmutableList<ModuleSplit> shards = standaloneApksGenerator.generateStandaloneApks(ImmutableList.of(bundleModule), standaloneApkOptimizations(OptimizationDimension.ABI));
assertThat(shards).hasSize(3);
assertThat(shards.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.STANDALONE);
VariantTargeting armVariantTargeting = mergeVariantTargeting(variantAbiTargeting(ARMEABI, ImmutableSet.of(X86, X86_64)), VARIANT_TARGETING_WITH_SDK_1);
VariantTargeting x86VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86, ImmutableSet.of(ARMEABI, X86_64)), VARIANT_TARGETING_WITH_SDK_1);
VariantTargeting x64VariantTargeting = mergeVariantTargeting(variantAbiTargeting(X86_64, ImmutableSet.of(ARMEABI, X86)), VARIANT_TARGETING_WITH_SDK_1);
assertThat(shards.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(armVariantTargeting, x64VariantTargeting, x86VariantTargeting);
for (ModuleSplit shard : shards) {
assertThat(extractPaths(shard.getEntries())).containsAtLeast("assets/file.txt", "dex/classes.dex", "res/drawable/image.jpg", "res/drawable-mdpi/image.jpg", "root/license.dat");
}
ApkTargeting armTargeting = apkAbiTargeting(ARMEABI, ImmutableSet.of(X86, X86_64));
ApkTargeting x86Targeting = apkAbiTargeting(X86, ImmutableSet.of(ARMEABI, X86_64));
ApkTargeting x64Targeting = apkAbiTargeting(X86_64, ImmutableSet.of(ARMEABI, X86));
ImmutableMap<ApkTargeting, ModuleSplit> shardsByTargeting = Maps.uniqueIndex(shards, ModuleSplit::getApkTargeting);
assertThat(shardsByTargeting.keySet()).containsExactly(armTargeting, x86Targeting, x64Targeting);
assertThat(extractPaths(shardsByTargeting.get(armTargeting).getEntries())).contains("lib/armeabi/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(armTargeting).getEntries())).containsNoneOf("lib/x86/libtest.so", "lib/x86_64/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(x86Targeting).getEntries())).contains("lib/x86/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(x86Targeting).getEntries())).containsNoneOf("lib/armeabi/libtest.so", "lib/x86_64/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(x64Targeting).getEntries())).contains("lib/x86_64/libtest.so");
assertThat(extractPaths(shardsByTargeting.get(x64Targeting).getEntries())).containsNoneOf("lib/armeabi/libtest.so", "lib/x86/libtest.so");
}
Aggregations