Search in sources :

Example 1 with MultiAbi

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

the class ModuleSplit method getSuffix.

/**
 * Returns the split suffix base name based on the targeting.
 *
 * <p>The split suffix cannot contain dashes as they are not allowed by the Android Framework. We
 * replace them with underscores instead.
 */
public String getSuffix() {
    if (isMasterSplit()) {
        return "";
    }
    StringJoiner suffixJoiner = new StringJoiner("_");
    // The dimensions below should be ordered by their priority.
    AbiTargeting abiTargeting = getApkTargeting().getAbiTargeting();
    if (!abiTargeting.getValueList().isEmpty()) {
        abiTargeting.getValueList().forEach(value -> suffixJoiner.add(formatAbi(value)));
    } else if (!abiTargeting.getAlternativesList().isEmpty()) {
        suffixJoiner.add("other_abis");
    }
    MultiAbiTargeting multiAbiTargeting = getApkTargeting().getMultiAbiTargeting();
    for (MultiAbi value : multiAbiTargeting.getValueList()) {
        suffixJoiner.add(MULTI_ABI_SUFFIX_JOINER.join(value.getAbiList().stream().map(ModuleSplit::formatAbi).collect(toImmutableList())));
    }
    // Alternatives without values are not supported for MultiAbiTargeting.
    SanitizerTargeting sanitizerTargeting = getApkTargeting().getSanitizerTargeting();
    for (Sanitizer sanitizer : sanitizerTargeting.getValueList()) {
        if (sanitizer.getAlias().equals(SanitizerAlias.HWADDRESS)) {
            suffixJoiner.add("hwasan");
        } else {
            throw new IllegalArgumentException("Unknown sanitizer");
        }
    }
    LanguageTargeting languageTargeting = getApkTargeting().getLanguageTargeting();
    if (!languageTargeting.getValueList().isEmpty()) {
        languageTargeting.getValueList().forEach(suffixJoiner::add);
    } else if (!languageTargeting.getAlternativesList().isEmpty()) {
        suffixJoiner.add("other_lang");
    }
    getApkTargeting().getScreenDensityTargeting().getValueList().forEach(value -> suffixJoiner.add(SCREEN_DENSITY_TO_PROTO_VALUE_MAP.inverse().get(value.getDensityAlias()).replace('-', '_')));
    TextureCompressionFormatTargeting textureFormatTargeting = getApkTargeting().getTextureCompressionFormatTargeting();
    if (!textureFormatTargeting.getValueList().isEmpty()) {
        textureFormatTargeting.getValueList().forEach(value -> suffixJoiner.add(Ascii.toLowerCase(value.getAlias().name())));
    } else if (!textureFormatTargeting.getAlternativesList().isEmpty()) {
        suffixJoiner.add("other_tcf");
    }
    getApkTargeting().getDeviceTierTargeting().getValueList().forEach(value -> suffixJoiner.add("tier_" + value.getValue()));
    return suffixJoiner.toString();
}
Also used : LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) AbiTargeting(com.android.bundle.Targeting.AbiTargeting) TextureCompressionFormatTargeting(com.android.bundle.Targeting.TextureCompressionFormatTargeting) SanitizerTargeting(com.android.bundle.Targeting.SanitizerTargeting) Sanitizer(com.android.bundle.Targeting.Sanitizer) MultiAbi(com.android.bundle.Targeting.MultiAbi) StringJoiner(java.util.StringJoiner) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting)

Example 2 with MultiAbi

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

the class AbiApexImagesSplitter method split.

/**
 * Generates {@link ModuleSplit} objects dividing the APEX images by ABI.
 */
@Override
public ImmutableCollection<ModuleSplit> split(ModuleSplit moduleSplit) {
    if (!moduleSplit.isApex()) {
        return ImmutableList.of(moduleSplit);
    }
    List<TargetedApexImage> allTargetedImages = moduleSplit.getApexConfig().get().getImageList();
    // A set of all MultiAbis (flattened for repeated values) for easy generation of alternatives.
    ImmutableSet<MultiAbi> allTargeting = allTargetedImages.stream().flatMap(image -> image.getTargeting().getMultiAbi().getValueList().stream()).collect(toImmutableSet());
    // This prevents O(n^2).
    ImmutableMap<String, ModuleEntry> apexPathToEntryMap = buildApexPathToEntryMap(allTargetedImages, moduleSplit);
    ImmutableList.Builder<ModuleSplit> splits = new ImmutableList.Builder<>();
    for (TargetedApexImage targetedApexImage : allTargetedImages) {
        ModuleEntry entry = apexPathToEntryMap.get(targetedApexImage.getPath());
        List<MultiAbi> targeting = targetedApexImage.getTargeting().getMultiAbi().getValueList();
        ModuleSplit.Builder splitBuilder = moduleSplit.toBuilder().setApkTargeting(moduleSplit.getApkTargeting().toBuilder().setMultiAbiTargeting(MultiAbiTargeting.newBuilder().addAllValue(targeting).addAllAlternatives(Sets.difference(allTargeting, ImmutableSet.copyOf(targeting)))).build()).setMasterSplit(false).setEntries(targetedApexImage.getBuildInfoPath().isEmpty() ? ImmutableList.of(entry) : ImmutableList.of(entry, apexPathToEntryMap.get(targetedApexImage.getBuildInfoPath())));
        splits.add(splitBuilder.build());
    }
    return splits.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) MultiAbiTargeting(com.android.bundle.Targeting.MultiAbiTargeting) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableCollection(com.google.common.collect.ImmutableCollection) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) List(java.util.List) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) Stream(java.util.stream.Stream) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) Function.identity(java.util.function.Function.identity) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) MultiAbi(com.android.bundle.Targeting.MultiAbi) ImmutableList(com.google.common.collect.ImmutableList) ModuleEntry(com.android.tools.build.bundletool.model.ModuleEntry) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetedApexImage(com.android.bundle.Files.TargetedApexImage) MultiAbi(com.android.bundle.Targeting.MultiAbi)

Aggregations

MultiAbi (com.android.bundle.Targeting.MultiAbi)2 MultiAbiTargeting (com.android.bundle.Targeting.MultiAbiTargeting)2 TargetedApexImage (com.android.bundle.Files.TargetedApexImage)1 AbiTargeting (com.android.bundle.Targeting.AbiTargeting)1 LanguageTargeting (com.android.bundle.Targeting.LanguageTargeting)1 Sanitizer (com.android.bundle.Targeting.Sanitizer)1 SanitizerTargeting (com.android.bundle.Targeting.SanitizerTargeting)1 TextureCompressionFormatTargeting (com.android.bundle.Targeting.TextureCompressionFormatTargeting)1 ModuleEntry (com.android.tools.build.bundletool.model.ModuleEntry)1 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)1 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 List (java.util.List)1 StringJoiner (java.util.StringJoiner)1