use of com.android.tools.build.bundletool.model.GeneratedApks in project bundletool by google.
the class AlternativeVariantTargetingPopulatorTest method systemApksPassThrough.
@Test
public void systemApksPassThrough() {
VariantTargeting emptySdkTargeting = variantSdkTargeting(SdkVersion.getDefaultInstance());
ImmutableList<ModuleSplit> systemSplits = ImmutableList.of(createModuleSplit(mergeVariantTargeting(emptySdkTargeting, variantDensityTargeting(DensityAlias.LDPI)), SplitType.SYSTEM));
GeneratedApks generatedApks = GeneratedApks.builder().setSystemApks(systemSplits).build();
GeneratedApks processedApks = AlternativeVariantTargetingPopulator.populateAlternativeVariantTargeting(generatedApks);
assertThat(processedApks.size()).isEqualTo(1);
assertThat(processedApks.getInstantApks()).isEmpty();
assertThat(processedApks.getStandaloneApks()).isEmpty();
assertThat(processedApks.getSplitApks()).isEmpty();
assertThat(processedApks.getArchivedApks()).isEmpty();
assertThat(processedApks.getSystemApks()).isEqualTo(systemSplits);
}
use of com.android.tools.build.bundletool.model.GeneratedApks 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.tools.build.bundletool.model.GeneratedApks in project bundletool by google.
the class ApkSerializerManager method serializeApks.
@VisibleForTesting
ImmutableList<Variant> serializeApks(Path outputDirectory, GeneratedApks generatedApks, Optional<DeviceSpec> deviceSpec) {
validateInput(generatedApks, apkBuildMode);
// Running with system APK mode generates a fused APK and additional unmatched language splits.
// To avoid filtering of unmatched language splits we skip device filtering for system mode.
Predicate<ModuleSplit> deviceFilter = deviceSpec.isPresent() && !apkBuildMode.equals(SYSTEM) ? new ApkMatcher(addDefaultDeviceTierIfNecessary(deviceSpec.get()))::matchesModuleSplitByTargeting : alwaysTrue();
ImmutableListMultimap<VariantKey, ModuleSplit> splitsByVariant = generatedApks.getAllApksGroupedByOrderedVariants();
// Assign the variant numbers to each variant present.
AtomicInteger variantNumberCounter = new AtomicInteger(firstVariantNumber);
ImmutableMap<VariantKey, Integer> variantNumberByVariantKey = splitsByVariant.keySet().stream().collect(toImmutableMap(identity(), unused -> variantNumberCounter.getAndIncrement()));
// 1. Remove APKs not matching the device spec.
// 2. Modify the APKs based on the ApkModifier.
// 3. Serialize all APKs in parallel.
// Modifies the APK using APK modifier, then returns a map by extracting the variant
// of APK first and later clearing out its variant targeting.
ImmutableListMultimap<VariantKey, ModuleSplit> finalSplitsByVariant = splitsByVariant.entries().stream().filter(keyModuleSplitEntry -> deviceFilter.test(keyModuleSplitEntry.getValue())).collect(groupingBySortedKeys(Entry::getKey, entry -> clearVariantTargeting(modifyApk(entry.getValue(), variantNumberByVariantKey.get(entry.getKey())))));
// After variant targeting of APKs are cleared, there might be duplicate APKs
// which are removed and the distinct APKs are then serialized in parallel.
ImmutableBiMap<ZipPath, ModuleSplit> splitsByRelativePath = finalSplitsByVariant.values().stream().distinct().collect(toImmutableBiMap(apkPathManager::getApkPath, identity()));
ImmutableMap<ZipPath, ApkDescription> apkDescriptionsByRelativePath = apkSerializer.serialize(outputDirectory, splitsByRelativePath);
// Build the result proto.
ImmutableList.Builder<Variant> variants = ImmutableList.builder();
for (VariantKey variantKey : finalSplitsByVariant.keySet()) {
Variant.Builder variant = Variant.newBuilder().setVariantNumber(variantNumberByVariantKey.get(variantKey)).setTargeting(variantKey.getVariantTargeting());
Multimap<BundleModuleName, ModuleSplit> splitsByModuleName = finalSplitsByVariant.get(variantKey).stream().collect(groupingBySortedKeys(ModuleSplit::getModuleName));
for (BundleModuleName moduleName : splitsByModuleName.keySet()) {
variant.addApkSet(ApkSet.newBuilder().setModuleMetadata(bundle.getModule(moduleName).getModuleMetadata()).addAllApkDescription(splitsByModuleName.get(moduleName).stream().map(split -> splitsByRelativePath.inverse().get(split)).map(apkDescriptionsByRelativePath::get).collect(toImmutableList())));
}
variants.add(variant.build());
}
return variants.build();
}
use of com.android.tools.build.bundletool.model.GeneratedApks in project bundletool by google.
the class SplitsXmlInjectorTest method process_archiveSplitTypes.
@Test
public void process_archiveSplitTypes() throws Exception {
ModuleSplit archived = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"", /* masterSplit= */
true, SplitType.ARCHIVE, /* languageTargeting= */
null);
ResourceTable archivedResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru-RU", "title ru-RU", "fr", "title fr")).build();
archived = archived.toBuilder().setResourceTable(archivedResourceTable).build();
GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(archived));
ModuleSplit processedArchivedApk = xmlInjectorProcess(generatedApks).stream().collect(onlyElement());
assertThat(processedArchivedApk.getAndroidManifest().getMetadataResourceId("com.android.vending.splits")).isEmpty();
}
use of com.android.tools.build.bundletool.model.GeneratedApks in project bundletool by google.
the class SplitsXmlInjectorTest method process_noLanguageTargeting.
@Test
public void process_noLanguageTargeting() throws Exception {
ResourceTable baseResourceTable = new ResourceTableBuilder().addPackage("com.example.app").addStringResourceForMultipleLocales("title", ImmutableMap.of("ru", "title ru-RU", "fr", "title fr", "es", "title es")).build();
ModuleSplit baseModule = createModuleSplit(BASE_MODULE_NAME.getName(), /* splitId= */
"", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null).toBuilder().setResourceTable(baseResourceTable).build();
ResourceTable featureResourceTable = new ResourceTableBuilder().addPackage("com.example.app.module").addStringResourceForMultipleLocales("module_str", ImmutableMap.of("ru", "module ru-RU")).build();
ModuleSplit featureModule = createModuleSplit("module", /* splitId= */
"module", /* masterSplit= */
true, SPLIT, /* languageTargeting= */
null).toBuilder().setResourceTable(featureResourceTable).build();
GeneratedApks generatedApks = GeneratedApks.fromModuleSplits(ImmutableList.of(baseModule, featureModule));
ModuleSplit processedBaseMasterSplit = xmlInjectorProcess(generatedApks).stream().filter(module -> module.isMasterSplit() && module.isBaseModuleSplit()).collect(onlyElement());
assertThat(processedBaseMasterSplit.getResourceTable().get()).containsResource("com.example.app:xml/splits0").withFileReference("res/xml/splits0.xml");
XmlNode expectedSplitsProtoXml = new SplitsProtoXmlBuilder().addLanguageMapping(BundleModuleName.create("module"), "ru", "module").addLanguageMapping(BASE_MODULE_NAME, "ru", "").addLanguageMapping(BASE_MODULE_NAME, "fr", "").addLanguageMapping(BASE_MODULE_NAME, "es", "").build();
Optional<ModuleEntry> splitsXml = processedBaseMasterSplit.findEntry("res/xml/splits0.xml");
assertThat(splitsXml).isPresent();
assertThat(XmlNode.parseFrom(splitsXml.get().getContent().read(), ExtensionRegistry.getEmptyRegistry())).ignoringRepeatedFieldOrder().isEqualTo(expectedSplitsProtoXml);
}
Aggregations