Search in sources :

Example 6 with BundleModuleName

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

the class BundleModuleMergerTest method testMultipleModulesWithInstallTime_implicitMergingDexRenaming.

@Test
public void testMultipleModulesWithInstallTime_implicitMergingDexRenaming() throws Exception {
    XmlNode installTimeModuleManifest = androidManifestForFeature("com.test.app.detail", withInstallTimeDelivery());
    createBasicZipBuilder(BUNDLE_CONFIG_1_0_0).addFileWithProtoContent(ZipPath.create("base/manifest/AndroidManifest.xml"), MANIFEST).addFileWithContent(ZipPath.create("base/dex/classes.dex"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("base/assets/baseAssetfile.txt"), DUMMY_CONTENT).addFileWithProtoContent(ZipPath.create("detail/manifest/AndroidManifest.xml"), installTimeModuleManifest).addFileWithContent(ZipPath.create("detail/assets/detailsAssetfile.txt"), DUMMY_CONTENT).addFileWithContent(ZipPath.create("detail/dex/classes.dex"), DUMMY_CONTENT).writeTo(bundleFile);
    try (ZipFile appBundleZip = new ZipFile(bundleFile.toFile())) {
        AppBundle appBundlePreMerge = AppBundle.buildFromZip(appBundleZip);
        AppBundle appBundlePostMerge = BundleModuleMerger.mergeNonRemovableInstallTimeModules(appBundlePreMerge, /* overrideBundleToolVersion = */
        false);
        assertThat(appBundlePostMerge.getModules().keySet().stream().map(BundleModuleName::getName)).containsExactly("base");
        assertThat(appBundlePreMerge.getModules().values().stream().mapToLong(module -> module.getEntries().size()).sum()).isEqualTo(appBundlePostMerge.getModules().values().stream().mapToLong(module -> module.getEntries().size()).sum());
        assertThat(appBundlePostMerge.getBaseModule().getEntry(ZipPath.create("dex/classes.dex"))).isPresent();
        assertThat(appBundlePostMerge.getBaseModule().getEntry(ZipPath.create("dex/classes2.dex"))).isPresent();
    }
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ManifestProtoUtils.withFeatureCondition(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withFeatureCondition) ManifestProtoUtils.withMetadataValue(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMetadataValue) ManifestProtoUtils.withSplitNameActivity(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameActivity) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ManifestProtoUtils.androidManifest(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest) BundleConfigBuilder(com.android.tools.build.bundletool.testing.BundleConfigBuilder) RunWith(org.junit.runner.RunWith) ZipBuilder(com.android.tools.build.bundletool.io.ZipBuilder) ManifestProtoUtils.androidManifestForAssetModule(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForAssetModule) ProtoTruth.assertThat(com.google.common.truth.extensions.proto.ProtoTruth.assertThat) ManifestProtoUtils.withOnDemandDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withOnDemandDelivery) ZipFile(java.util.zip.ZipFile) ManifestProtoUtils.androidManifestForMlModule(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForMlModule) ManifestProtoUtils.withSplitNameService(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withSplitNameService) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Path(java.nio.file.Path) Before(org.junit.Before) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) TestData(com.android.tools.build.bundletool.TestData) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) ManifestProtoUtils.withInstallTimeRemovableElement(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeRemovableElement) File(java.io.File) Correspondence(com.google.common.truth.Correspondence) ManifestProtoUtils.withMinSdkVersion(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withMinSdkVersion) Stream(java.util.stream.Stream) Rule(org.junit.Rule) XmlNode(com.android.aapt.Resources.XmlNode) BundleConfig(com.android.bundle.Config.BundleConfig) ManifestProtoUtils.withInstallTimeDelivery(com.android.tools.build.bundletool.testing.ManifestProtoUtils.withInstallTimeDelivery) ManifestProtoUtils.androidManifestForFeature(com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifestForFeature) AppBundle(com.android.tools.build.bundletool.model.AppBundle) TemporaryFolder(org.junit.rules.TemporaryFolder) XmlNode(com.android.aapt.Resources.XmlNode) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 7 with BundleModuleName

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

the class FusingAndroidManifestMergerTest method mergeChildrenMode_metadataWithoutName_notMerged.

@Test
public void mergeChildrenMode_metadataWithoutName_notMerged() {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("meta-data").addChildElement(XmlProtoElementBuilder.create("data"))))), androidManifestForFeature("com.testapp.feature", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("meta-data").addChildElement(XmlProtoElementBuilder.create("action"))))));
    AndroidManifest merged = createMerger(Mode.MERGE_CHILDREN).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", withActivity("myActivity", activity -> activity.addChildElement(XmlProtoElementBuilder.create("meta-data").addChildElement(XmlProtoElementBuilder.create("action"))))));
    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 8 with BundleModuleName

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

the class FusingAndroidManifestMergerTest method mergeFeatureElementsIntoBaseManifest.

@Test
@Theory
public void mergeFeatureElementsIntoBaseManifest(FusingAndroidManifestMerger.Mode mode) {
    SetMultimap<BundleModuleName, AndroidManifest> manifests = createManifests(androidManifest("com.testapp", withSplitNameService("onlyBaseService", "base"), withSplitNameService("baseAndFeatureService", "base"), withSplitNameActivity("myActivity", "base")), androidManifestForFeature("com.testapp.feature1", withSplitNameService("baseAndFeatureService", "feature1"), withSplitNameActivity("anotherActivity", "feature1")), androidManifestForFeature("com.testapp.feature2", withSplitNameService("justFeatureService", "feature2"), withSplitNameActivity("myActivity", "feature2")));
    AndroidManifest merged = createMerger(mode).merge(manifests);
    AndroidManifest expected = AndroidManifest.create(androidManifest("com.testapp", withSplitNameService("onlyBaseService", "base"), withSplitNameService("baseAndFeatureService", "feature1"), withSplitNameActivity("myActivity", "feature2"), withSplitNameActivity("anotherActivity", "feature1"), withSplitNameService("justFeatureService", "feature2")));
    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) Theory(org.junit.experimental.theories.Theory)

Example 9 with BundleModuleName

use of com.android.tools.build.bundletool.model.BundleModuleName 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 10 with BundleModuleName

use of com.android.tools.build.bundletool.model.BundleModuleName 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)

Aggregations

BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)26 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)19 Test (org.junit.Test)14 ZipPath (com.android.tools.build.bundletool.model.ZipPath)6 BundleModule (com.android.tools.build.bundletool.model.BundleModule)5 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)5 ImmutableList (com.google.common.collect.ImmutableList)5 AppBundle (com.android.tools.build.bundletool.model.AppBundle)4 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)4 HashMap (java.util.HashMap)4 BundleConfig (com.android.bundle.Config.BundleConfig)3 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)3 CommandExecutionException (com.android.tools.build.bundletool.model.exceptions.CommandExecutionException)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ResourceTable (com.android.aapt.Resources.ResourceTable)2 DeviceSpec (com.android.bundle.Devices.DeviceSpec)2 TargetedAssetsDirectory (com.android.bundle.Files.TargetedAssetsDirectory)2 Predicates.not (com.google.common.base.Predicates.not)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2