Search in sources :

Example 96 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class ModuleSplitterTest method resolvesSplitIdSuffixes_singleVariant.

/**
 * Tests that modules belonging to same variant with potentially same splitId, are resolved to
 * different splitIds.
 */
@Test
public void resolvesSplitIdSuffixes_singleVariant() throws Exception {
    // Note: this test will be extended once we add support for new directory groups.
    ModuleSplit assetsSplit1 = ModuleSplit.builder().setModuleName(BundleModuleName.create("base")).setEntries(ImmutableList.of()).setApkTargeting(apkTextureTargeting(textureCompressionTargeting(ATC, ImmutableSet.of(S3TC)))).setMasterSplit(false).setAndroidManifest(AndroidManifest.create(androidManifest("com.test.app"))).setVariantTargeting(VariantTargeting.getDefaultInstance()).build();
    ModuleSplit assetsSplit2 = ModuleSplit.builder().setModuleName(BundleModuleName.create("base")).setEntries(ImmutableList.of()).setApkTargeting(apkTextureTargeting(textureCompressionTargeting(ATC, ImmutableSet.of(ETC1_RGB8)))).setMasterSplit(false).setAndroidManifest(AndroidManifest.create(androidManifest("com.test.app"))).setVariantTargeting(VariantTargeting.getDefaultInstance()).build();
    BundleModule bundleModule = new BundleModuleBuilder("base").setManifest(androidManifest("com.test.app")).build();
    ModuleSplitter moduleSplitter = ModuleSplitter.createForTest(bundleModule, BUNDLETOOL_VERSION);
    assetsSplit1 = moduleSplitter.writeSplitIdInManifest(assetsSplit1);
    assetsSplit2 = moduleSplitter.writeSplitIdInManifest(assetsSplit2);
    assertThat(assetsSplit1.getAndroidManifest().getSplitId()).hasValue("config.atc");
    assertThat(assetsSplit2.getAndroidManifest().getSplitId()).hasValue("config.atc_2");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 97 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class ModuleSplitterTest method splitNameRemovedForInstalledSplit.

@Test
public void splitNameRemovedForInstalledSplit() throws Exception {
    XmlNode manifest = androidManifest("com.test.app", withMainActivity("MainActivity"), withSplitNameActivity("FooActivity", "foo"));
    BundleModule bundleModule = new BundleModuleBuilder("testModule").setManifest(manifest).build();
    ImmutableList<ModuleSplit> moduleSplits = ModuleSplitter.createForTest(bundleModule, BUNDLETOOL_VERSION).splitModule();
    assertThat(moduleSplits).hasSize(1);
    ModuleSplit masterSplit = moduleSplits.get(0);
    ImmutableList<XmlElement> activities = masterSplit.getAndroidManifest().getManifestRoot().getElement().getChildElement("application").getChildrenElements(ACTIVITY_ELEMENT_NAME).map(XmlProtoElement::getProto).collect(toImmutableList());
    assertThat(activities).hasSize(2);
    XmlElement activityElement = activities.get(1);
    assertThat(activityElement.getAttributeList()).containsExactly(xmlAttribute(ANDROID_NAMESPACE_URI, "name", NAME_RESOURCE_ID, "FooActivity"));
}
Also used : XmlNode(com.android.aapt.Resources.XmlNode) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) XmlElement(com.android.aapt.Resources.XmlElement) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 98 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class ModuleSplitterTest method addingLibraryPlaceholders_baseModule.

@Test
public void addingLibraryPlaceholders_baseModule() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).build();
    ModuleSplitter moduleSplitter = ModuleSplitter.createNoStamp(baseModule, BUNDLETOOL_VERSION, APP_BUNDLE, ApkGenerationConfiguration.builder().setAbisForPlaceholderLibs(ImmutableSet.of(toAbi(AbiAlias.X86), toAbi(AbiAlias.ARM64_V8A))).build(), lPlusVariantTargeting(), ImmutableSet.of("base"));
    ImmutableList<ModuleSplit> splits = moduleSplitter.splitModule();
    assertThat(splits).hasSize(1);
    ModuleSplit masterSplit = splits.get(0);
    assertThat(masterSplit.isMasterSplit()).isTrue();
    assertThat(extractPaths(masterSplit.getEntries())).containsExactly("dex/classes.dex", "lib/x86/libplaceholder.so", "lib/arm64-v8a/libplaceholder.so");
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 99 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class NativeLibrariesCompressionSplitterTest method otherEntriesCompressionUnchanged.

@Test
public void otherEntriesCompressionUnchanged() throws Exception {
    NativeLibrariesCompressionSplitter nativeLibrariesCompressionSplitter = createSplitterWithEnabledUncompressedLibraries();
    BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("lib/x86_64/libsome.so").addFile("assets/leftover.txt").addFile("dex/classes.dex").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).setManifest(androidManifest("com.test.app")).build();
    ImmutableCollection<ModuleSplit> splits = nativeLibrariesCompressionSplitter.split(ModuleSplit.forModule(bundleModule, variantSdkTargeting(ANDROID_M_API_VERSION)));
    assertThat(splits).hasSize(1);
    assertThat(splits).hasSize(1);
    ModuleSplit moduleSplit = Iterables.getOnlyElement(splits);
    assertThat(moduleSplit.getVariantTargeting()).isEqualTo(variantSdkTargeting(ANDROID_M_API_VERSION));
    assertThat(extractPaths(moduleSplit.getEntries())).containsExactly("lib/x86_64/libsome.so", "assets/leftover.txt", "dex/classes.dex");
    assertThat(moduleSplit.isMasterSplit()).isTrue();
    assertThat(getEntry(moduleSplit.getEntries(), "lib/x86_64/libsome.so").getForceUncompressed()).isTrue();
    assertThat(getEntry(moduleSplit.getEntries(), "assets/leftover.txt").getForceUncompressed()).isFalse();
    assertThat(getEntry(moduleSplit.getEntries(), "dex/classes.dex").getForceUncompressed()).isFalse();
    assertThat(moduleSplit.getApkTargeting()).isEqualToDefaultInstance();
    assertThat(compareManifestMutators(moduleSplit.getMasterManifestMutators(), withExtractNativeLibs(false))).isTrue();
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 100 with BundleModuleBuilder

use of com.android.tools.build.bundletool.testing.BundleModuleBuilder in project bundletool by google.

the class NativeLibsCompressionVariantGeneratorTest method variantsWithoutNativeLibs.

@Test
public void variantsWithoutNativeLibs() throws Exception {
    NativeLibsCompressionVariantGenerator nativeLibsCompressionVariantGenerator = new NativeLibsCompressionVariantGenerator(ApkGenerationConfiguration.builder().setEnableUncompressedNativeLibraries(true).build());
    BundleModule bundleModule = new BundleModuleBuilder("testModule").addFile("assets/leftover.txt").addFile("dex/classes.dex").setManifest(androidManifest("com.test.app")).build();
    ImmutableCollection<VariantTargeting> splits = nativeLibsCompressionVariantGenerator.generate(bundleModule).collect(toImmutableList());
    assertThat(splits).isEmpty();
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Aggregations

BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)349 Test (org.junit.Test)348 BundleModule (com.android.tools.build.bundletool.model.BundleModule)321 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)164 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)69 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)44 ResourceTable (com.android.aapt.Resources.ResourceTable)38 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)28 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)19 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)16 Truth.assertThat (com.google.common.truth.Truth.assertThat)16 RunWith (org.junit.runner.RunWith)16 TestUtils.extractPaths (com.android.tools.build.bundletool.testing.TestUtils.extractPaths)15 ImmutableList (com.google.common.collect.ImmutableList)15 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)15 ProtoTruth.assertThat (com.google.common.truth.extensions.proto.ProtoTruth.assertThat)15 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)14 NativeLibraries (com.android.bundle.Files.NativeLibraries)13 HDPI (com.android.tools.build.bundletool.testing.ResourcesTableFactory.HDPI)13 USER_PACKAGE_OFFSET (com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET)13