Search in sources :

Example 61 with BundleModule

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);
    }
}
Also used : BundleModule(com.android.tools.build.bundletool.model.BundleModule) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 62 with BundleModule

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();
        }
    }
}
Also used : BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Example 63 with BundleModule

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);
    }
}
Also used : ZipPath(com.android.tools.build.bundletool.model.ZipPath) BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Example 64 with BundleModule

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule)

Example 65 with BundleModule

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")))));
}
Also used : Iterables(com.google.common.collect.Iterables) MDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) ResourcesTableFactory.locale(com.android.tools.build.bundletool.testing.ResourcesTableFactory.locale) RunWith(org.junit.runner.RunWith) TestUtils.extractPaths(com.android.tools.build.bundletool.testing.TestUtils.extractPaths) ResourcesTableFactory.resourceTable(com.android.tools.build.bundletool.testing.ResourcesTableFactory.resourceTable) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ImmutableList(com.google.common.collect.ImmutableList) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourcesTableFactory.mergeConfigs(com.android.tools.build.bundletool.testing.ResourcesTableFactory.mergeConfigs) Map(java.util.Map) ResourcesTableFactory.entry(com.android.tools.build.bundletool.testing.ResourcesTableFactory.entry) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Predicates(com.google.common.base.Predicates) DensityAlias(com.android.bundle.Targeting.ScreenDensity.DensityAlias) ResourcesTableFactory.pkg(com.android.tools.build.bundletool.testing.ResourcesTableFactory.pkg) ResourcesTableFactory.type(com.android.tools.build.bundletool.testing.ResourcesTableFactory.type) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ResourceTable(com.android.aapt.Resources.ResourceTable) ResourcesTableFactory.value(com.android.tools.build.bundletool.testing.ResourcesTableFactory.value) ConfigValue(com.android.aapt.Resources.ConfigValue) ImmutableMap(com.google.common.collect.ImmutableMap) USER_PACKAGE_OFFSET(com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET) HDPI(com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) TestCase.fail(junit.framework.TestCase.fail) ResourcesTableFactory(com.android.tools.build.bundletool.testing.ResourcesTableFactory) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) Maps(com.google.common.collect.Maps) ResourcesTableFactory.fileReference(com.android.tools.build.bundletool.testing.ResourcesTableFactory.fileReference) TargetingUtils.apkDensityTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkDensityTargeting) ByteString(com.google.protobuf.ByteString) StringPool(com.android.aapt.Resources.StringPool) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Ignore(org.junit.Ignore) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) TargetingUtils.apkLanguageTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkLanguageTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ResourceTable(com.android.aapt.Resources.ResourceTable) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

BundleModule (com.android.tools.build.bundletool.model.BundleModule)404 Test (org.junit.Test)370 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)321 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)158 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)112 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)42 ResourceTable (com.android.aapt.Resources.ResourceTable)40 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)29 ImmutableList (com.google.common.collect.ImmutableList)27 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)24 ImmutableSet (com.google.common.collect.ImmutableSet)22 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)21 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)19 AppBundle (com.android.tools.build.bundletool.model.AppBundle)15 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)15 TestUtils.extractPaths (com.android.tools.build.bundletool.testing.TestUtils.extractPaths)15 Truth.assertThat (com.google.common.truth.Truth.assertThat)15 RunWith (org.junit.runner.RunWith)15 Assets (com.android.bundle.Files.Assets)14 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)14