Search in sources :

Example 76 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.

the class FusingAndroidManifestMerger method merge.

private AndroidManifest merge(Map<BundleModuleName, AndroidManifest> manifests) {
    AndroidManifest baseManifest = manifests.get(BASE_MODULE_NAME);
    List<AndroidManifest> featureManifests = manifests.entrySet().stream().filter(entry -> !BASE_MODULE_NAME.equals(entry.getKey())).sorted(Comparator.comparing(entry -> entry.getKey().getName())).map(Map.Entry::getValue).collect(toImmutableList());
    if (featureManifests.isEmpty()) {
        return baseManifest;
    }
    return mergeManifests(baseManifest, featureManifests);
}
Also used : Iterables(com.google.common.collect.Iterables) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) XmlProtoAttributeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoAttributeBuilder) BASE_MODULE_NAME(com.android.tools.build.bundletool.model.BundleModuleName.BASE_MODULE_NAME) Function(java.util.function.Function) Predicates.not(com.google.common.base.Predicates.not) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) XmlProtoNodeBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoNodeBuilder) XmlProtoElement(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElement) MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) XmlProtoElementBuilder(com.android.tools.build.bundletool.model.utils.xmlproto.XmlProtoElementBuilder) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) Streams.stream(com.google.common.collect.Streams.stream) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) AutoValue(com.google.auto.value.AutoValue) Optional(java.util.Optional) ManifestEditor(com.android.tools.build.bundletool.model.ManifestEditor) Comparator(java.util.Comparator) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 77 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.

the class AndroidManifestValidator method validateInstant.

private static void validateInstant(BundleModule module) {
    AndroidManifest manifest = module.getAndroidManifest();
    Optional<Boolean> isInstantModule = manifest.isInstantModule();
    if (isInstantModule.orElse(false)) {
        // if it is an instant module, ensure that max sdk is > 21, as we cannot serve anything less
        Optional<Integer> maxSdk = manifest.getMaxSdkVersion();
        if (maxSdk.isPresent() && maxSdk.get() < MIN_INSTANT_SDK_VERSION) {
            throw InvalidBundleException.builder().withUserMessage("maxSdkVersion (%d) is less than minimum sdk allowed for instant apps (%d).", maxSdk.get(), MIN_INSTANT_SDK_VERSION).build();
        }
    }
}
Also used : AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest)

Example 78 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.

the class AndroidManifestValidator method validateAssetModuleManifest.

private static void validateAssetModuleManifest(BundleModule module) {
    ImmutableMultimap<String, String> allowedManifestElementChildren = ImmutableMultimap.of(DISTRIBUTION_NAMESPACE_URI, "module", NO_NAMESPACE_URI, "uses-split");
    AndroidManifest manifest = module.getAndroidManifest();
    if (!manifest.getModuleType().equals(ModuleType.ASSET_MODULE)) {
        return;
    }
    if (manifest.getManifestRoot().getElement().getChildrenElements().anyMatch(child -> !allowedManifestElementChildren.containsEntry(child.getNamespaceUri(), child.getName()))) {
        throw InvalidBundleException.builder().withUserMessage("Unexpected element declaration in manifest of asset pack '%s'.", module.getName()).build();
    }
}
Also used : AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest)

Example 79 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.

the class SdkAndroidManifestValidator method validateModule.

@Override
public void validateModule(BundleModule module) {
    AndroidManifest manifest = module.getAndroidManifest();
    validateSingleSdkLibrary(manifest);
    validateVersioningTagsSet(manifest);
    validateInternalOnlyIfInstallLocationSet(manifest);
    validateNoPermissions(manifest);
    validateNoSharedUserId(manifest);
    validateNoComponents(manifest);
    validateNoSplitId(manifest);
}
Also used : AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest)

Example 80 with AndroidManifest

use of com.android.tools.build.bundletool.model.AndroidManifest in project bundletool by google.

the class SameTargetingMergerTest method mergerRejects_conflictingManifests.

/**
 * At the moment, the merger doesn't support merging two different android manifests so we check
 * that we reject cases where manifest is different within a set chosen for unification.
 */
@Test
public void mergerRejects_conflictingManifests() throws Exception {
    AndroidManifest manifest1 = AndroidManifest.create(androidManifest("com.test.app1"));
    AndroidManifest manifest2 = AndroidManifest.create(androidManifest("com.test.app2"));
    ModuleSplit split1 = createModuleSplitBuilder().setAndroidManifest(manifest1).build();
    ModuleSplit split2 = createModuleSplitBuilder().setAndroidManifest(manifest2).build();
    Throwable exception = assertThrows(IllegalStateException.class, () -> new SameTargetingMerger().merge(ImmutableList.of(split1, split2)));
    assertThat(exception).hasMessageThat().contains("two distinct manifests");
}
Also used : ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

Aggregations

AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)130 Test (org.junit.Test)115 ImmutableList (com.google.common.collect.ImmutableList)94 AppBundleBuilder (com.android.tools.build.bundletool.testing.AppBundleBuilder)90 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)89 Truth.assertThat (com.google.common.truth.Truth.assertThat)89 RunWith (org.junit.runner.RunWith)89 ImmutableSet (com.google.common.collect.ImmutableSet)87 AppBundle (com.android.tools.build.bundletool.model.AppBundle)84 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)82 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)81 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)80 ZipPath (com.android.tools.build.bundletool.model.ZipPath)80 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)79 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)79 Path (java.nio.file.Path)79 AppBundleSerializer (com.android.tools.build.bundletool.io.AppBundleSerializer)78 Files (java.nio.file.Files)78 Before (org.junit.Before)78 Rule (org.junit.Rule)78