Search in sources :

Example 86 with AndroidManifest

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

the class FusingAndroidManifestMergerTest method mergeChildrenMode_gatherAllMetadataAndIntentFilters.

@Test
public void mergeChildrenMode_gatherAllMetadataAndIntentFilters() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("baseAction", "baseAction2"), /* 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())));
    AndroidManifest merged = createMerger(Mode.MERGE_CHILDREN).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", activityWithIntentFiltersAndMetadata("myActivity", /* intentFilters= */
    ImmutableList.of("feature1Action", "feature2Action", "baseAction", "baseAction2"), /* metadata= */
    ImmutableList.of("feature1Meta", "baseMeta"))));
    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 87 with AndroidManifest

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

the class FusingAndroidManifestMergerTest method mergeFeatureActivitiesIntoBaseManifest.

@Test
@Theory
public void mergeFeatureActivitiesIntoBaseManifest(FusingAndroidManifestMerger.Mode mode) {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withCustomThemeActivity("activity1", BASE_THEME_REF_ID), withCustomThemeActivity("activity2", BASE_THEME_REF_ID), withCustomThemeActivity("activity3", BASE_THEME_REF_ID)), androidManifestForFeature("com.testapp.feature1", withCustomThemeActivity("activity1", FEATURE1_THEME_REF_ID)), androidManifestForFeature("com.testapp.feature2", withCustomThemeActivity("activity3", FEATURE2_THEME_REF_ID)));
    AndroidManifest merged = createMerger(mode).merge(manifests);
    Map<String, Integer> refIdByActivity = Maps.transformValues(merged.getActivitiesByName(), activity -> activity.getAndroidAttribute(THEME_RESOURCE_ID).get().getValueAsRefId());
    assertThat(merged.getPackageName()).isEqualTo("com.testapp");
    assertThat(refIdByActivity).containsExactly("activity1", FEATURE1_THEME_REF_ID, "activity2", BASE_THEME_REF_ID, "activity3", FEATURE2_THEME_REF_ID).inOrder();
}
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 88 with AndroidManifest

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

the class FusingAndroidManifestMergerTest method duplicateManifest_throws.

@Test
public void duplicateManifest_throws() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = ImmutableSetMultimap.of(BASE_MODULE_NAME, AndroidManifest.create(androidManifest("com.testapp1")), BASE_MODULE_NAME, AndroidManifest.create(androidManifest("com.testapp2")));
    CommandExecutionException exception = assertThrows(CommandExecutionException.class, () -> createMerger(Mode.REPLACE).merge(manifests));
    assertThat(exception).hasMessageThat().isEqualTo("Expected exactly one base module manifest, but found 2.");
}
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 89 with AndroidManifest

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

the class ModuleSplitsToShardMergerTest method manifests_valid_fuseFeatureApplicationElementsIntoBaseManifest.

@Test
public void manifests_valid_fuseFeatureApplicationElementsIntoBaseManifest() throws Exception {
    AndroidManifest manifestBase = AndroidManifest.create(androidManifest("com.test.app1", withCustomThemeActivity("activity1", 1), withCustomThemeActivity("activity2", 2)));
    AndroidManifest manifestFeat = AndroidManifest.create(androidManifest("com.test.app2", withCustomThemeActivity("activity1", 3), withMetadataValue("moduleMeta", "module"), withSplitNameActivityAlias("moduleActivityAlias", "module"), withSplitNameProvider("moduleProvider", "module"), withSplitNameReceiver("moduleReceiver", "module"), withSplitNameService("moduleService", "module")));
    ModuleSplit split1 = createModuleSplitBuilder().setAndroidManifest(manifestBase).setModuleName(BundleModuleName.create("base")).build();
    ModuleSplit split2 = createModuleSplitBuilder().setAndroidManifest(manifestFeat).setModuleName(BundleModuleName.create("module")).build();
    ModuleSplit shard = splitsToShardMerger.mergeSingleShard(ImmutableList.of(split1, split2), createCache());
    assertThat(shard.getAndroidManifest().getPackageName()).isEqualTo("com.test.app1");
    assertThat(extractActivityThemeRefIds(shard.getAndroidManifest())).containsExactly("activity1", 3, "activity2", 2);
    assertThat(extractApplicationElements(shard.getAndroidManifest())).containsExactly("activity1", ACTIVITY_ELEMENT_NAME, "activity2", ACTIVITY_ELEMENT_NAME, "moduleMeta", META_DATA_ELEMENT_NAME, "moduleActivityAlias", ACTIVITY_ALIAS_ELEMENT_NAME, "moduleProvider", PROVIDER_ELEMENT_NAME, "moduleReceiver", RECEIVER_ELEMENT_NAME, "moduleService", SERVICE_ELEMENT_NAME, "com.android.dynamic.apk.fused.modules", META_DATA_ELEMENT_NAME);
}
Also used : ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) Test(org.junit.Test)

Example 90 with AndroidManifest

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

the class ModuleSplitsToShardMergerTest method manifests_valid_mergeFeatureActivitiesIntoBaseManifest_versionBefore_1_8_0.

@Test
public void manifests_valid_mergeFeatureActivitiesIntoBaseManifest_versionBefore_1_8_0() throws Exception {
    TestComponent.useTestModule(this, TestModule.builder().withBundletoolVersion("1.7.0").build());
    AndroidManifest manifestBase = AndroidManifest.create(androidManifest("com.test.app1", withCustomThemeActivity("activity1", 1), withCustomThemeActivity("activity2", 2)));
    AndroidManifest manifestFeat = AndroidManifest.create(androidManifest("com.test.app2", withCustomThemeActivity("activity1", 3), withMetadataValue("moduleMeta", "module"), withSplitNameActivityAlias("moduleActivityAlias", "module"), withSplitNameProvider("moduleProvider", "module"), withSplitNameReceiver("moduleReceived", "module"), withSplitNameService("moduleService", "module")));
    ModuleSplit split1 = createModuleSplitBuilder().setAndroidManifest(manifestBase).setModuleName(BundleModuleName.create("base")).build();
    ModuleSplit split2 = createModuleSplitBuilder().setAndroidManifest(manifestFeat).setModuleName(BundleModuleName.create("module")).build();
    ModuleSplit shard = splitsToShardMerger.mergeSingleShard(ImmutableList.of(split1, split2), createCache());
    assertThat(shard.getAndroidManifest().getPackageName()).isEqualTo("com.test.app1");
    assertThat(extractActivityThemeRefIds(shard.getAndroidManifest())).containsExactly("activity1", 3, "activity2", 2);
    assertThat(extractApplicationElements(shard.getAndroidManifest())).containsExactly("activity1", ACTIVITY_ELEMENT_NAME, "activity2", ACTIVITY_ELEMENT_NAME, "com.android.dynamic.apk.fused.modules", META_DATA_ELEMENT_NAME);
}
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