Search in sources :

Example 46 with AndroidManifest

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

the class ModuleSplitsToShardMergerTest method manifests_noBaseManifest_throws.

@Test
public void manifests_noBaseManifest_throws() throws Exception {
    AndroidManifest manifest1 = AndroidManifest.create(androidManifest("com.test.app1"));
    AndroidManifest manifest2 = AndroidManifest.create(androidManifest("com.test.app2"));
    ModuleSplit split1 = createModuleSplitBuilder().setAndroidManifest(manifest1).setModuleName(BundleModuleName.create("module1")).build();
    ModuleSplit split2 = createModuleSplitBuilder().setAndroidManifest(manifest2).setModuleName(BundleModuleName.create("module2")).build();
    Throwable exception = assertThrows(CommandExecutionException.class, () -> splitsToShardMerger.mergeSingleShard(ImmutableList.of(split1, split2), createCache()));
    assertThat(exception).hasMessageThat().contains("Expected to have base module");
}
Also used : ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

Example 47 with AndroidManifest

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

the class FusingAndroidManifestMergerTest method replaceMode_fullyReplaceBaseElement.

@Test
public void replaceMode_fullyReplaceBaseElement() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("baseAction"), /* metadata= */
    ImmutableList.of("baseMeta")), activityWithIntentFiltersAndMetadata("anotherActivity", /* intentFilters= */
    ImmutableList.of("baseAction"), /* metadata= */
    ImmutableList.of("baseMeta"))), androidManifestForFeature("com.testapp.feature1", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("feature1Action"), /* metadata= */
    ImmutableList.of("feature1Meta"))), androidManifestForFeature("com.testapp.feature2", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("feature2Action"), /* metadata= */
    ImmutableList.of()), activityWithIntentFiltersAndMetadata("anotherActivity", /* intentFilters= */
    ImmutableList.of("feature2Action"), /* metadata= */
    ImmutableList.of())));
    AndroidManifest merged = createMerger(Mode.REPLACE).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("feature1Action"), /* metadata= */
    ImmutableList.of("feature1Meta")), activityWithIntentFiltersAndMetadata("anotherActivity", /* intentFilters= */
    ImmutableList.of("feature2Action"), /* metadata= */
    ImmutableList.of())));
    assertThat(merged).isEqualTo(expected);
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

Example 48 with AndroidManifest

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

the class FusingAndroidManifestMergerTest method mergeChildrenMode_conflictMetadata_throws.

@Test
public void mergeChildrenMode_conflictMetadata_throws() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("meta-data").addAttribute(XmlProtoAttributeBuilder.createAndroidAttribute(NAME_ATTRIBUTE_NAME, NAME_RESOURCE_ID).setValueAsString("meta")).addChildText("Base text")))), androidManifestForFeature("com.testapp.feature1", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("meta-data").addAttribute(XmlProtoAttributeBuilder.createAndroidAttribute(NAME_ATTRIBUTE_NAME, NAME_RESOURCE_ID).setValueAsString("meta")).addChildText("Feature text")))));
    CommandExecutionException exception = assertThrows(CommandExecutionException.class, () -> createMerger(Mode.MERGE_CHILDREN).merge(manifests));
    assertThat(exception).hasMessageThat().contains("Multiple meta-data entries with the same name are found inside activity:myActivity");
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) Test(org.junit.Test)

Example 49 with AndroidManifest

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

the class FusingAndroidManifestMergerTest method onlyBaseManifest.

@Test
@Theory
public void onlyBaseManifest(FusingAndroidManifestMerger.Mode mode) {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withDebuggableAttribute(true), withCustomThemeActivity("activity", BASE_THEME_REF_ID)));
    AndroidManifest merged = createMerger(mode).merge(manifests);
    assertThat(merged).isEqualTo(getOnlyElement(manifests.get(BASE_MODULE_NAME)));
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 50 with AndroidManifest

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

the class FusingAndroidManifestMergerTest method noBaseManifest_throws.

@Test
public void noBaseManifest_throws() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = ImmutableSetMultimap.of(BundleModuleName.create("feature"), AndroidManifest.create(androidManifest("com.testapp")));
    CommandExecutionException exception = assertThrows(CommandExecutionException.class, () -> createMerger(Mode.REPLACE).merge(manifests));
    assertThat(exception).hasMessageThat().isEqualTo("Expected to have base module.");
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) 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