use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ResourceTableValidator method checkResourceIds.
@VisibleForTesting
void checkResourceIds(ImmutableList<BundleModule> modules) {
BundleModule baseModule = BundleValidationUtils.expectBaseModule(modules);
if (baseModule.getAndroidManifest().getIsolatedSplits().orElse(false)) {
// If splits are isolated, resource IDs cannot be duplicated between modules included in
// fusing. It's ok to have inter-module duplication for modules not included in fusing, but we
// still need to check for uniqueness within each module.
ImmutableList<BundleModule> modulesIncludedInFusing = modules.stream().filter(BundleModule::isIncludedInFusing).collect(toImmutableList());
checkResourceIdsAreUnique(modulesIncludedInFusing);
for (BundleModule module : modules) {
if (!module.isIncludedInFusing()) {
checkResourceIdsAreUnique(ImmutableList.of(module));
}
}
} else {
checkResourceIdsAreUnique(modules);
}
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class TextureCompressionFormatParityValidator method validateAllModulesSupportSameFormats.
/**
* Ensure the textutre formats are consistent across all modules.
*/
private static void validateAllModulesSupportSameFormats(ImmutableList<BundleModule> modules) {
BundleModule referentialModule = null;
SupportedTextureCompressionFormats referentialTextureCompressionFormats = null;
for (BundleModule module : modules) {
SupportedTextureCompressionFormats moduleTextureCompressionFormats = getSupportedTextureCompressionFormats(module);
if (moduleTextureCompressionFormats.getFormats().isEmpty()) {
continue;
}
if (referentialTextureCompressionFormats == null) {
referentialModule = module;
referentialTextureCompressionFormats = moduleTextureCompressionFormats;
} else if (!referentialTextureCompressionFormats.equals(moduleTextureCompressionFormats)) {
throw InvalidBundleException.builder().withUserMessage("All modules with targeted textures must have the same set of texture formats, but" + " module '%s' has formats %s and module '%s' has formats %s.", referentialModule.getName(), referentialTextureCompressionFormats, module.getName(), moduleTextureCompressionFormats).build();
}
}
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class ValidatorRunner method validateSdkBundleUsingSubValidator.
private static void validateSdkBundleUsingSubValidator(SdkBundle bundle, SubValidator subValidator) {
subValidator.validateSdkBundle(bundle);
BundleModule module = bundle.getModule();
subValidator.validateModule(module);
for (ZipPath moduleFile : getModuleFiles(module)) {
subValidator.validateModuleFile(moduleFile);
}
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class AssetSlicesGenerator method generateAssetSlices.
public ImmutableList<ModuleSplit> generateAssetSlices() {
ImmutableList.Builder<ModuleSplit> splits = ImmutableList.builder();
Optional<Integer> appVersionCode = appBundle.isAssetOnly() ? Optional.empty() : appBundle.getBaseModule().getAndroidManifest().getVersionCode();
for (BundleModule module : appBundle.getAssetModules().values()) {
AssetModuleSplitter moduleSplitter = new AssetModuleSplitter(module, apkGenerationConfiguration);
splits.addAll(moduleSplitter.splitModule().stream().map(split -> {
if (module.getDeliveryType().equals(ModuleDeliveryType.NO_INITIAL_INSTALL)) {
// In slices for on-demand and fast-follow asset modules the version name
// instead of the version code is set, since their version code is not used by
// Android.
Optional<String> nonUpfrontAssetModulesVersionName = (assetModulesVersionOverride.isPresent() ? assetModulesVersionOverride : appVersionCode).map(Object::toString);
return addVersionName(split, nonUpfrontAssetModulesVersionName);
} else {
// Install-time assets module have the same version code as the app.
return addVersionCode(split, appVersionCode);
}
}).collect(toImmutableList()));
}
return splits.build();
}
use of com.android.tools.build.bundletool.model.BundleModule in project bundletool by google.
the class LanguageResourcesSplitterTest method resourcesPinnedToMasterSplit_mixedWithDefaultStrings.
@Test
public void resourcesPinnedToMasterSplit_mixedWithDefaultStrings() throws Exception {
ResourceTable resourceTable = new ResourceTableBuilder().addPackage("com.test.app").addStringResource("default_label", "label").addStringResourceForMultipleLocales("pinned_label", ImmutableMap.of("en", "yes")).addStringResourceForMultipleLocales("split_label", ImmutableMap.of("en", "no")).build();
BundleModule module = new BundleModuleBuilder("testModule").setResourceTable(resourceTable).setManifest(androidManifest("com.test.app")).build();
ModuleSplit baseSplit = ModuleSplit.forResources(module);
LanguageResourcesSplitter languageSplitter = new LanguageResourcesSplitter(// pinned_label
resource -> resource.getResourceId().getFullResourceId() == 0x7f010001);
Collection<ModuleSplit> languageSplits = languageSplitter.split(baseSplit);
assertThat(languageSplits).hasSize(2);
ModuleSplit masterSplit = languageSplits.stream().filter(split -> split.isMasterSplit()).collect(onlyElement());
assertThat(masterSplit.getResourceTable()).hasValue(new ResourceTableBuilder().addPackage("com.test.app").addStringResource("default_label", "label").addStringResourceForMultipleLocales("pinned_label", ImmutableMap.of("en", "yes")).build());
ModuleSplit configSplit = languageSplits.stream().filter(split -> !split.isMasterSplit()).collect(onlyElement());
assertThat(configSplit.getApkTargeting()).isEqualTo(apkLanguageTargeting("en"));
assertThat(configSplit.getResourceTable()).hasValue(getStringResourceTable("split_label", 0x02, ImmutableList.of(value("no", locale("en")))));
}
Aggregations