Search in sources :

Example 6 with ModuleEntry

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

the class ModuleSplitterTest method masterSplit_hasAllOtherApkComponents.

@Test
public void masterSplit_hasAllOtherApkComponents() throws Exception {
    BundleModule testModule = new BundleModuleBuilder("testModule").setManifest(androidManifest("com.test.app")).addFile("assets/some_asset.txt").addFile("dex/classes.dex").addFile("root/some_other_file.txt").build();
    ImmutableList<ModuleSplit> splits = createAbiAndDensitySplitter(testModule).splitModule();
    assertThat(splits.stream().map(ModuleSplit::getSplitType).distinct().collect(toImmutableSet())).containsExactly(SplitType.SPLIT);
    assertThat(splits.stream().map(ModuleSplit::getVariantTargeting).distinct().collect(toImmutableSet())).containsExactly(lPlusVariantTargeting());
    // the example has nothing to split on.
    assertThat(splits).hasSize(1);
    ModuleSplit masterSplit = splits.get(0);
    assertThat(masterSplit.getApkTargeting()).isEqualTo(DEFAULT_MASTER_SPLIT_SDK_TARGETING);
    assertThat(masterSplit.isMasterSplit()).isTrue();
    ImmutableSet<String> actualFiles = masterSplit.getEntries().stream().map(ModuleEntry::getPath).map(ZipPath::toString).collect(toImmutableSet());
    ImmutableSet<String> expectedFiles = ImmutableSet.of("dex/classes.dex", "assets/some_asset.txt", "root/some_other_file.txt");
    assertThat(actualFiles).containsAtLeastElementsIn(expectedFiles);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 7 with ModuleEntry

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

the class SuffixStripperTest method removeAssetsTargeting_tcf.

@Test
public void removeAssetsTargeting_tcf() {
    ModuleSplit split = ModuleSplit.builder().setModuleName(BundleModuleName.create("base")).setApkTargeting(ApkTargeting.getDefaultInstance()).setVariantTargeting(VariantTargeting.getDefaultInstance()).setAndroidManifest(AndroidManifest.create(androidManifest("com.test.app"))).setMasterSplit(true).setEntries(ImmutableList.of(createModuleEntryForFile("assets/untargeted_texture.dat", DUMMY_CONTENT), createModuleEntryForFile("assets/textures#tcf_etc1/texture.dat", DUMMY_CONTENT), createModuleEntryForFile("assets/textures#tcf_etc1/other_texture.dat", DUMMY_CONTENT))).setAssetsConfig(assets(targetedAssetsDirectory("assets/textures#tcf_etc1", assetsDirectoryTargeting(textureCompressionTargeting(ETC1_RGB8))))).build();
    ModuleSplit strippedSplit = SuffixStripper.createForDimension(SplitDimension.Value.TEXTURE_COMPRESSION_FORMAT).removeAssetsTargeting(split);
    // Check that the ATC and untargeted sibling folders have been excluded, and suffix has been
    // stripped.
    assertThat(strippedSplit.getEntries()).hasSize(3);
    assertThat(strippedSplit.getEntries().stream().map(ModuleEntry::getPath)).containsExactly(ZipPath.create("assets/untargeted_texture.dat"), ZipPath.create("assets/textures/texture.dat"), ZipPath.create("assets/textures/other_texture.dat"));
    assertThat(strippedSplit.getAssetsConfig().get().getDirectoryCount()).isEqualTo(1);
    assertThat(strippedSplit.getAssetsConfig().get().getDirectory(0).getPath()).isEqualTo("assets/textures");
    // Check that the APK and Variant targeting were applied.
    assertThat(strippedSplit.getApkTargeting()).isEqualToDefaultInstance();
    assertThat(strippedSplit.getVariantTargeting()).isEqualToDefaultInstance();
}
Also used : ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) Test(org.junit.Test)

Example 8 with ModuleEntry

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

the class SystemApksGeneratorTest method uncompressedDexFiles_enabled.

@Test
public void uncompressedDexFiles_enabled() throws Exception {
    BundleModule baseModule = new BundleModuleBuilder("base").addFile("dex/classes.dex").setManifest(androidManifestForFeature("com.test.app")).build();
    ApkOptimizations apkOptimizations = splitOptimizations().toBuilder().setUncompressDexFiles(true).build();
    ImmutableList<ModuleSplit> shards = systemApksGenerator.generateSystemApks(/* modules= */
    ImmutableList.of(baseModule), /* modulesToFuse= */
    ImmutableSet.of(BASE_MODULE_NAME), apkOptimizations);
    assertThat(shards).hasSize(1);
    ModuleSplit fatApk = shards.get(0);
    assertThat(fatApk.findEntry("dex/classes.dex").map(ModuleEntry::getForceUncompressed)).hasValue(true);
}
Also used : BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test)

Example 9 with ModuleEntry

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

the class LocaleConfigXmlInjector method injectLocaleConfigXml.

private static ModuleSplit injectLocaleConfigXml(ModuleSplit split, XmlNode xmlNode) {
    ResourceInjector resourceInjector = ResourceInjector.fromModuleSplit(split);
    ResourceId resourceId = resourceInjector.addResource(XML_TYPE_NAME, createXmlEntry());
    ModuleEntry localesConfigEntry = addLocalesConfigEntry(xmlNode);
    return split.toBuilder().setResourceTable(resourceInjector.build()).setEntries(ImmutableList.<ModuleEntry>builder().addAll(split.getEntries()).add(localesConfigEntry).build()).setAndroidManifest(split.getAndroidManifest().toEditor().setLocaleConfig(resourceId.getFullResourceId()).save()).build();
}
Also used : ResourceId(com.android.tools.build.bundletool.model.ResourceId) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ResourceInjector(com.android.tools.build.bundletool.model.ResourceInjector)

Example 10 with ModuleEntry

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

the class SplitsXmlInjector method injectSplitsXml.

private static ModuleSplit injectSplitsXml(ModuleSplit split, XmlNode xmlNode) {
    ZipPath resourcePath = getUniqueResourcePath(split);
    ResourceInjector resourceInjector = ResourceInjector.fromModuleSplit(split);
    ResourceId resourceId = resourceInjector.addResource(XML_TYPE_NAME, createXmlEntry(resourcePath));
    return split.toBuilder().setResourceTable(resourceInjector.build()).setEntries(ImmutableList.<ModuleEntry>builder().addAll(split.getEntries()).add(ModuleEntry.builder().setPath(resourcePath).setContent(ByteSource.wrap(xmlNode.toByteArray())).build()).build()).setAndroidManifest(split.getAndroidManifest().toEditor().addMetaDataResourceId(METADATA_KEY, resourceId.getFullResourceId()).save()).build();
}
Also used : ResourceId(com.android.tools.build.bundletool.model.ResourceId) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ResourceInjector(com.android.tools.build.bundletool.model.ResourceInjector)

Aggregations

ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)41 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)22 ZipPath (com.android.tools.build.bundletool.model.ZipPath)18 ImmutableList (com.google.common.collect.ImmutableList)18 Test (org.junit.Test)13 BundleModule (com.android.tools.build.bundletool.model.BundleModule)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 SpecialModuleEntry (com.android.tools.build.bundletool.model.BundleModule.SpecialModuleEntry)8 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)6 HashMap (java.util.HashMap)6 Optional (java.util.Optional)6 TargetedAssetsDirectory (com.android.bundle.Files.TargetedAssetsDirectory)5 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)5 IOException (java.io.IOException)5 Map (java.util.Map)5 ResourceTable (com.android.aapt.Resources.ResourceTable)4 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)4 BundleModuleName (com.android.tools.build.bundletool.model.BundleModuleName)4 ApkOptimizations (com.android.tools.build.bundletool.optimizations.ApkOptimizations)4