use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class SplitApksGenerator method generateSplitApks.
private ImmutableList<ModuleSplit> generateSplitApks(ImmutableList<BundleModule> modules, ApkGenerationConfiguration apkGenerationConfiguration, VariantTargeting variantTargeting) {
ImmutableSet<String> allModuleNames = modules.stream().map(module -> module.getName().getName()).collect(toImmutableSet());
ImmutableList.Builder<ModuleSplit> splits = ImmutableList.builder();
for (BundleModule module : modules) {
ModuleSplitter moduleSplitter = ModuleSplitter.create(module, bundletoolVersion, appBundle, apkGenerationConfiguration, variantTargeting, allModuleNames, stampSource.map(SourceStamp::getSource), StampType.STAMP_TYPE_DISTRIBUTION_APK);
splits.addAll(moduleSplitter.splitModule());
}
return splits.build();
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class EntryClashValidator method validateAllModules.
@Override
public void validateAllModules(ImmutableList<BundleModule> modules) {
if (!BundleValidationUtils.isAssetOnlyBundle(modules)) {
BundleModule baseModule = BundleValidationUtils.expectBaseModule(modules);
boolean isolatedSplits = baseModule.getAndroidManifest().getIsolatedSplits().orElse(false);
if (isolatedSplits) {
// manager instances.
return;
}
}
checkEntryClashes(modules);
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ModuleNamesValidator method validateAllModules.
@Override
public void validateAllModules(ImmutableList<BundleModule> modules) {
Set<BundleModuleName> moduleNames = new HashSet<>();
for (BundleModule module : modules) {
Optional<String> splitId = module.getAndroidManifest().getSplitId();
BundleModuleName moduleName = module.getName();
boolean isFeatureModule = module.getAndroidManifest().getModuleType().isFeatureModule();
if (moduleName.equals(BundleModuleName.BASE_MODULE_NAME)) {
if (splitId.isPresent()) {
throw InvalidBundleException.builder().withUserMessage("The base module should not have the 'split' attribute set in the " + "AndroidManifest.xml").build();
}
} else {
if (splitId.isPresent()) {
if (!splitId.get().equals(moduleName.getName())) {
throw InvalidBundleException.builder().withUserMessage("The 'split' attribute in the AndroidManifest.xml of modules must be the name " + "of the module, but has the value '%s' in module '%s'", splitId.get(), moduleName).build();
}
} else {
throw InvalidBundleException.builder().withUserMessage("No 'split' attribute found in the AndroidManifest.xml of module '%s'.", moduleName).build();
}
}
boolean alreadyPresent = !moduleNames.add(moduleName);
if (alreadyPresent) {
if (splitId.isPresent()) {
throw InvalidBundleException.builder().withUserMessage("More than one module have the 'split' attribute set to '%s' in the " + "AndroidManifest.xml.", splitId.get()).build();
} else if (isFeatureModule) {
throw InvalidBundleException.builder().withUserMessage("More than one module was found without the 'split' attribute set in the" + " AndroidManifest.xml. Ensure that all the dynamic features have the" + " 'split' attribute correctly set in the AndroidManifest.xml.").build();
}
}
}
if (!BundleValidationUtils.isAssetOnlyBundle(modules) && !moduleNames.contains(BundleModuleName.BASE_MODULE_NAME)) {
throw InvalidBundleException.builder().withUserMessage("No base module found. At least one module must not have a 'split' attribute set in" + " the AndroidManifest.xml.").build();
}
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ModuleTitleValidator method checkModuleTitles.
private static void checkModuleTitles(ImmutableList<BundleModule> modules) {
if (BundleValidationUtils.isAssetOnlyBundle(modules)) {
return;
}
BundleModule baseModule = BundleValidationUtils.expectBaseModule(modules);
boolean isolatedSplits = baseModule.getAndroidManifest().getIsolatedSplits().orElse(false);
// For bundles built using older versions we haven't strictly enforced module Title Validation.
Version bundleVersion = BundleToolVersion.getVersionFromBundleConfig(baseModule.getBundleConfig());
if (!MODULE_TITLE_VALIDATION_ENFORCED.enabledForVersion(bundleVersion)) {
return;
}
ResourceTable table = baseModule.getResourceTable().orElse(ResourceTable.getDefaultInstance());
ImmutableSet<Integer> stringResourceIds = entries(table).filter(entry -> entry.getType().getName().equals("string")).map(entry -> entry.getResourceId().getFullResourceId()).collect(toImmutableSet());
for (BundleModule module : modules) {
if (module.getModuleType().equals(ModuleType.ASSET_MODULE)) {
if (module.getAndroidManifest().getTitleRefId().isPresent()) {
throw InvalidBundleException.builder().withUserMessage("Module titles not supported in asset packs, but found in '%s'.", module.getName()).build();
}
} else if (!module.getDeliveryType().equals(ModuleDeliveryType.ALWAYS_INITIAL_INSTALL)) {
Optional<Integer> titleRefId = module.getAndroidManifest().getTitleRefId();
if (isolatedSplits) {
// references into the base split resource table.
return;
}
if (!titleRefId.isPresent()) {
throw InvalidBundleException.builder().withUserMessage("Mandatory title is missing in manifest for module '%s'.", module.getName()).build();
}
if (!stringResourceIds.contains(titleRefId.get())) {
throw InvalidBundleException.builder().withUserMessage("Title for module '%s' is missing in the base resource table.", module.getName()).build();
}
}
}
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ResourceTableValidator method checkResourceIdsAreUnique.
private static void checkResourceIdsAreUnique(ImmutableList<BundleModule> modules) {
HashSet<ResourceId> usedResourceIds = newHashSet();
for (BundleModule module : modules) {
ResourceTable resourceTable = module.getResourceTable().orElse(ResourceTable.getDefaultInstance());
ResourcesUtils.entries(resourceTable).forEach(resourceTableEntry -> {
boolean foundDuplicate = !usedResourceIds.add(resourceTableEntry.getResourceId());
if (foundDuplicate) {
throw InvalidBundleException.builder().withUserMessage("Duplicate resource id (%s).", resourceTableEntry.getResourceId().toString()).build();
}
});
}
}
Aggregations