Search in sources :

Example 1 with SameTargetingMerger

use of com.android.tools.build.bundletool.mergers.SameTargetingMerger in project bundletool by google.

the class ModuleSplitter method runSplitters.

private ImmutableList<ModuleSplit> runSplitters() {
    if (targetsOnlyPreL(module)) {
        throw CommandExecutionException.builder().withInternalMessage("Cannot split module '%s' because it does not target devices on Android L or above.", module.getName()).build();
    }
    ImmutableList.Builder<ModuleSplit> splits = ImmutableList.builder();
    // Resources splits.
    SplittingPipeline resourcesPipeline = createResourcesSplittingPipeline();
    splits.addAll(resourcesPipeline.split(ModuleSplit.forResources(module, variantTargeting)));
    // Native libraries splits.
    SplittingPipeline nativePipeline = createNativeLibrariesSplittingPipeline();
    splits.addAll(nativePipeline.split(ModuleSplit.forNativeLibraries(module, variantTargeting)));
    // Assets splits.
    SplittingPipeline assetsPipeline = createAssetsSplittingPipeline();
    splits.addAll(assetsPipeline.split(ModuleSplit.forAssets(module, variantTargeting)));
    // Dex Files.
    SplittingPipeline dexPipeline = createDexSplittingPipeline();
    splits.addAll(dexPipeline.split(ModuleSplit.forDex(module, variantTargeting)));
    // Other files.
    splits.add(ModuleSplit.forRoot(module, variantTargeting));
    // Merging and making a master split.
    ImmutableList<ModuleSplit> mergedSplits = new SameTargetingMerger().merge(applyMasterManifestMutators(splits.build()));
    // Check that we have only one split with default targeting - the master split.
    ImmutableList<ModuleSplit> defaultTargetingSplits = mergedSplits.stream().filter(split -> split.getApkTargeting().equals(ApkTargeting.getDefaultInstance())).collect(toImmutableList());
    checkState(defaultTargetingSplits.size() == 1, "Expected one split with default targeting.");
    return mergedSplits;
}
Also used : ApkTargeting(com.android.bundle.Targeting.ApkTargeting) SuffixManager(com.android.tools.build.bundletool.model.SuffixManager) OptimizationDimension(com.android.tools.build.bundletool.model.OptimizationDimension) SdkVersion(com.android.bundle.Targeting.SdkVersion) AndroidManifest(com.android.tools.build.bundletool.model.AndroidManifest) ImmutableCollection(com.google.common.collect.ImmutableCollection) TargetingUtils.getMinSdk(com.android.tools.build.bundletool.model.targeting.TargetingUtils.getMinSdk) SdkVersionTargeting(com.android.bundle.Targeting.SdkVersionTargeting) PIN_LOWEST_DENSITY_OF_EACH_STYLE_TO_MASTER(com.android.tools.build.bundletool.model.version.VersionGuardedFeature.PIN_LOWEST_DENSITY_OF_EACH_STYLE_TO_MASTER) SameTargetingMerger(com.android.tools.build.bundletool.mergers.SameTargetingMerger) ResourceId(com.android.tools.build.bundletool.model.ResourceId) ResourceTableEntry(com.android.tools.build.bundletool.model.ResourceTableEntry) ImmutableList(com.google.common.collect.ImmutableList) ManifestMutator(com.android.tools.build.bundletool.model.ManifestMutator) Predicates(com.google.common.base.Predicates) Version(com.android.tools.build.bundletool.model.version.Version) VariantTargeting(com.android.bundle.Targeting.VariantTargeting) Int32Value(com.google.protobuf.Int32Value) ImmutableSet(com.google.common.collect.ImmutableSet) CommandExecutionException(com.android.tools.build.bundletool.model.exceptions.CommandExecutionException) Predicate(java.util.function.Predicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) StampType(com.android.tools.build.bundletool.model.SourceStamp.StampType) BundleMetadata(com.android.tools.build.bundletool.model.BundleMetadata) ANDROID_L_API_VERSION(com.android.tools.build.bundletool.model.utils.Versions.ANDROID_L_API_VERSION) TargetingProtoUtils.sdkVersionFrom(com.android.tools.build.bundletool.model.utils.TargetingProtoUtils.sdkVersionFrom) SplitType(com.android.tools.build.bundletool.model.ModuleSplit.SplitType) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) BundleConfig(com.android.bundle.Config.BundleConfig) Optional(java.util.Optional) ManifestEditor(com.android.tools.build.bundletool.model.ManifestEditor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModule(com.android.tools.build.bundletool.model.BundleModule) TargetingProtoUtils.lPlusVariantTargeting(com.android.tools.build.bundletool.model.utils.TargetingProtoUtils.lPlusVariantTargeting) Configuration(com.android.aapt.ConfigurationOuterClass.Configuration) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) SameTargetingMerger(com.android.tools.build.bundletool.mergers.SameTargetingMerger)

Example 2 with SameTargetingMerger

use of com.android.tools.build.bundletool.mergers.SameTargetingMerger in project bundletool by google.

the class ModuleSplitterForShards method generateSplits.

/**
 * Generates a flat list of splits from a bundle module.
 */
public ImmutableList<ModuleSplit> generateSplits(BundleModule module, ImmutableSet<OptimizationDimension> shardingDimensions) {
    ImmutableList.Builder<ModuleSplit> rawSplits = ImmutableList.builder();
    // Native libraries splits.
    SplittingPipeline nativePipeline = createNativeLibrariesSplittingPipeline(shardingDimensions);
    rawSplits.addAll(nativePipeline.split(ModuleSplit.forNativeLibraries(module)));
    // Resources splits.
    SplittingPipeline resourcesPipeline = createResourcesSplittingPipeline(shardingDimensions);
    rawSplits.addAll(resourcesPipeline.split(ModuleSplit.forResources(module)));
    // Apex images splits.
    SplittingPipeline apexPipeline = createApexImagesSplittingPipeline();
    rawSplits.addAll(apexPipeline.split(ModuleSplit.forApex(module)));
    // Assets splits.
    SplittingPipeline assetsPipeline = createAssetsSplittingPipeline(shardingDimensions);
    rawSplits.addAll(assetsPipeline.split(ModuleSplit.forAssets(module)));
    // Other files.
    rawSplits.add(ModuleSplit.forDex(module));
    rawSplits.add(ModuleSplit.forRoot(module));
    ImmutableList<ModuleSplit> unmergedSplits = rawSplits.build();
    // Strip assets for some dimensions (texture compression format).
    ImmutableList<ModuleSplit> unmergedStrippedSplits = stripAssetsWithTargeting(unmergedSplits);
    // Merge splits with the same targeting and make a single master split.
    ImmutableList<ModuleSplit> mergedSplits = new SameTargetingMerger().merge(unmergedStrippedSplits);
    // Remove the splitName from any standalone apks, as these are only used for instant apps (L+).
    mergedSplits = mergedSplits.stream().map(ModuleSplit::removeSplitName).collect(toImmutableList());
    // Check that we have only one master split.
    long masterSplitCount = mergedSplits.stream().filter(ModuleSplit::isMasterSplit).count();
    checkState(masterSplitCount == 1, "Expected one master split, got %s.", masterSplitCount);
    return mergedSplits;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SplittingPipeline(com.android.tools.build.bundletool.splitters.SplittingPipeline) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) SameTargetingMerger(com.android.tools.build.bundletool.mergers.SameTargetingMerger)

Aggregations

SameTargetingMerger (com.android.tools.build.bundletool.mergers.SameTargetingMerger)2 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Configuration (com.android.aapt.ConfigurationOuterClass.Configuration)1 BundleConfig (com.android.bundle.Config.BundleConfig)1 ApkTargeting (com.android.bundle.Targeting.ApkTargeting)1 SdkVersion (com.android.bundle.Targeting.SdkVersion)1 SdkVersionTargeting (com.android.bundle.Targeting.SdkVersionTargeting)1 VariantTargeting (com.android.bundle.Targeting.VariantTargeting)1 AndroidManifest (com.android.tools.build.bundletool.model.AndroidManifest)1 AppBundle (com.android.tools.build.bundletool.model.AppBundle)1 BundleMetadata (com.android.tools.build.bundletool.model.BundleMetadata)1 BundleModule (com.android.tools.build.bundletool.model.BundleModule)1 ManifestEditor (com.android.tools.build.bundletool.model.ManifestEditor)1 ManifestMutator (com.android.tools.build.bundletool.model.ManifestMutator)1 SplitType (com.android.tools.build.bundletool.model.ModuleSplit.SplitType)1 OptimizationDimension (com.android.tools.build.bundletool.model.OptimizationDimension)1 ResourceId (com.android.tools.build.bundletool.model.ResourceId)1 ResourceTableEntry (com.android.tools.build.bundletool.model.ResourceTableEntry)1