Search in sources :

Example 31 with ApkTargeting

use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.

the class MergingUtilsTest method mergeShardTargetings_firstAbiSecondLanguage_ok.

@Test
public void mergeShardTargetings_firstAbiSecondLanguage_ok() {
    ApkTargeting targeting1 = apkAbiTargeting(AbiAlias.X86);
    ApkTargeting targeting2 = apkLanguageTargeting("fr");
    ApkTargeting merged = MergingUtils.mergeShardTargetings(targeting1, targeting2);
    assertThat(merged).isEqualTo(ApkTargeting.newBuilder().setAbiTargeting(abiTargeting(AbiAlias.X86)).setLanguageTargeting(languageTargeting("fr")).build());
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) Test(org.junit.Test)

Example 32 with ApkTargeting

use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.

the class MergingUtilsTest method mergeShardTargetings_oneSubsetOfTheOther_ok.

@Test
public void mergeShardTargetings_oneSubsetOfTheOther_ok() {
    ApkTargeting targeting1 = apkAbiTargeting(AbiAlias.X86);
    ApkTargeting targeting2 = mergeApkTargeting(targeting1, apkDensityTargeting(DensityAlias.HDPI));
    ApkTargeting merged = MergingUtils.mergeShardTargetings(targeting1, targeting2);
    assertThat(merged).isEqualTo(targeting2);
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) Test(org.junit.Test)

Example 33 with ApkTargeting

use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.

the class MergingUtilsTest method mergeShardTargetings_differentAbis_ok.

@Test
public void mergeShardTargetings_differentAbis_ok() {
    ApkTargeting targeting1 = apkAbiTargeting(AbiAlias.X86, ImmutableSet.of(AbiAlias.X86_64, AbiAlias.MIPS));
    ApkTargeting targeting2 = apkAbiTargeting(AbiAlias.X86_64, ImmutableSet.of(AbiAlias.X86, AbiAlias.MIPS));
    ApkTargeting merged = MergingUtils.mergeShardTargetings(targeting1, targeting2);
    assertThat(merged).ignoringRepeatedFieldOrder().isEqualTo(apkAbiTargeting(ImmutableSet.of(AbiAlias.X86, AbiAlias.X86_64), ImmutableSet.of(AbiAlias.MIPS)));
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) Test(org.junit.Test)

Example 34 with ApkTargeting

use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.

the class MergingUtilsTest method mergeShardTargetings_nonAbiNonDensityNonLanguageTargeting_throws.

@Test
public void mergeShardTargetings_nonAbiNonDensityNonLanguageTargeting_throws() {
    ApkTargeting targeting = apkMinSdkTargeting(21);
    CommandExecutionException exception = assertThrows(CommandExecutionException.class, () -> MergingUtils.mergeShardTargetings(targeting, apkLanguageTargeting("en")));
    assertThat(exception).hasMessageThat().contains("Expecting only ABI, screen density, language and texture compression format" + " targeting");
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) TargetingUtils.mergeApkTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) Test(org.junit.Test)

Example 35 with ApkTargeting

use of com.android.bundle.Targeting.ApkTargeting in project bundletool by google.

the class ModuleSplitsToShardMerger method mergeSingleShard.

/**
 * Gets a list of splits, and merges them into a single standalone APK (aka shard).
 *
 * <p>Allows to customize split type {@code mergedSplitType} of merged shard and Android manifest
 * merger {@code manifestMerger}.
 */
public ModuleSplit mergeSingleShard(ImmutableCollection<ModuleSplit> splitsOfShard, Map<ImmutableSet<ModuleEntry>, ImmutableList<Path>> mergedDexCache, SplitType mergedSplitType, AndroidManifestMerger manifestMerger) {
    ListMultimap<BundleModuleName, ModuleEntry> dexFilesToMergeByModule = ArrayListMultimap.create();
    // If multiple splits were generated from one module, we'll see the same manifest multiple
    // times. The multimap filters out identical (module name, manifest) pairs by contract.
    // All splits of a module should have the same manifest, so the following multimap should
    // associate just one value with each key. This is checked explicitly for the base module
    // because the manifest merger requires *single* base manifest.
    SetMultimap<BundleModuleName, AndroidManifest> androidManifestsToMergeByModule = HashMultimap.create();
    Map<ZipPath, ModuleEntry> mergedEntriesByPath = new HashMap<>();
    Optional<ResourceTable> mergedResourceTable = Optional.empty();
    Map<String, TargetedAssetsDirectory> mergedAssetsConfig = new HashMap<>();
    ApkTargeting mergedSplitTargeting = ApkTargeting.getDefaultInstance();
    for (ModuleSplit split : splitsOfShard) {
        // Resource tables and Split targetings can be merged for each split individually as we go.
        mergedResourceTable = mergeResourceTables(mergedResourceTable, split);
        mergedSplitTargeting = mergeSplitTargetings(mergedSplitTargeting, split);
        // Android manifests need to be merged later, globally for all splits.
        androidManifestsToMergeByModule.put(split.getModuleName(), split.getAndroidManifest());
        for (ModuleEntry entry : split.getEntries()) {
            if (entry.getPath().startsWith(DEX_DIRECTORY)) {
                // Dex files need to be merged later, globally for all splits.
                dexFilesToMergeByModule.put(split.getModuleName(), entry);
            } else {
                mergeEntries(mergedEntriesByPath, split, entry);
            }
        }
        split.getAssetsConfig().ifPresent(assetsConfig -> {
            mergeTargetedAssetsDirectories(mergedAssetsConfig, assetsConfig.getDirectoryList());
        });
    }
    AndroidManifest mergedAndroidManifest = manifestMerger.merge(androidManifestsToMergeByModule);
    Collection<ModuleEntry> mergedDexFiles = mergeDexFilesAndCache(dexFilesToMergeByModule, mergedAndroidManifest, mergedDexCache);
    // Record names of the modules this shard was fused from.
    ImmutableList<String> fusedModuleNames = getUniqueModuleNames(splitsOfShard);
    if (mergedSplitType.equals(SplitType.STANDALONE)) {
        mergedAndroidManifest = mergedAndroidManifest.toEditor().setFusedModuleNames(fusedModuleNames).save();
    }
    // Construct the final shard.
    return buildShard(mergedEntriesByPath.values(), mergedDexFiles, mergedSplitTargeting, mergedAndroidManifest, mergedResourceTable, mergedAssetsConfig, mergedSplitType);
}
Also used : BundleModuleName(com.android.tools.build.bundletool.model.BundleModuleName) TargetedAssetsDirectory(com.android.bundle.Files.TargetedAssetsDirectory) ApkTargeting(com.android.bundle.Targeting.ApkTargeting) HashMap(java.util.HashMap) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ZipPath(com.android.tools.build.bundletool.model.ZipPath) ResourceTable(com.android.aapt.Resources.ResourceTable)

Aggregations

ApkTargeting (com.android.bundle.Targeting.ApkTargeting)49 Test (org.junit.Test)44 TargetingUtils.mergeApkTargeting (com.android.tools.build.bundletool.testing.TargetingUtils.mergeApkTargeting)28 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)22 BundleModule (com.android.tools.build.bundletool.model.BundleModule)18 BundleModuleBuilder (com.android.tools.build.bundletool.testing.BundleModuleBuilder)18 ResourceTableBuilder (com.android.tools.build.bundletool.testing.ResourceTableBuilder)10 ResourceTable (com.android.aapt.Resources.ResourceTable)8 DensityAlias (com.android.bundle.Targeting.ScreenDensity.DensityAlias)7 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableSet (com.google.common.collect.ImmutableSet)7 ApexImages (com.android.bundle.Files.ApexImages)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)6 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)6 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)5 ZipPath (com.android.tools.build.bundletool.model.ZipPath)5 ManifestProtoUtils.androidManifest (com.android.tools.build.bundletool.testing.ManifestProtoUtils.androidManifest)5 MDPI (com.android.tools.build.bundletool.testing.ResourcesTableFactory.MDPI)5 USER_PACKAGE_OFFSET (com.android.tools.build.bundletool.testing.ResourcesTableFactory.USER_PACKAGE_OFFSET)5 ImmutableMap (com.google.common.collect.ImmutableMap)5