Search in sources :

Example 1 with AbiTargeting

use of com.android.bundle.Targeting.AbiTargeting 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 AbiTargeting

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

the class ShardedApksFacadeTest method singleModule_withNativeLibsAndDensity_strip64bitNativeLibs.

@Test
@Theory
public void singleModule_withNativeLibsAndDensity_strip64bitNativeLibs(@FromDataPoints("standaloneSplitTypes") SplitType standaloneSplitType) throws Exception {
    Optimizations optimizations = Optimizations.newBuilder().setStandaloneConfig(StandaloneConfig.newBuilder().setStrip64BitLibraries(true)).build();
    TestComponent.useTestModule(this, standaloneSplitType.equals(SplitType.SYSTEM) ? TestModule.builder().withDeviceSpec(DEVICE_SPEC).withBundleConfig(BundleConfig.newBuilder().setOptimizations(optimizations)).build() : TestModule.builder().withBundleConfig(BundleConfig.newBuilder().setOptimizations(optimizations)).build());
    ImmutableList<BundleModule> bundleModule = ImmutableList.of(new BundleModuleBuilder("base").addFile("lib/x86/libsome.so").addFile("lib/x86_64/libsome.so").setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/x86", nativeDirectoryTargeting(X86)), targetedNativeDirectory("lib/x86_64", nativeDirectoryTargeting(AbiAlias.X86_64)))).addFile("res/drawable-ldpi/image.jpg").addFile("res/drawable-mdpi/image.jpg").setResourceTable(new ResourceTableBuilder().addPackage("com.test.app").addDrawableResourceForMultipleDensities("image", ImmutableMap.of(LDPI_VALUE, "res/drawable-ldpi/image.jpg", MDPI_VALUE, "res/drawable-mdpi/image.jpg")).build()).setManifest(androidManifest("com.test.app")).build());
    ImmutableList<ModuleSplit> moduleSplits;
    if (standaloneSplitType.equals(SplitType.SYSTEM)) {
        moduleSplits = shardedApksFacade.generateSystemSplits(bundleModule, ImmutableSet.of(BASE_MODULE_NAME), DEFAULT_APK_OPTIMIZATIONS);
        // x86, mdpi split
        assertThat(moduleSplits).hasSize(1);
    } else {
        moduleSplits = shardedApksFacade.generateSplits(bundleModule, DEFAULT_APK_OPTIMIZATIONS);
        // 7 (density), 1 (abi) split
        assertThat(moduleSplits).hasSize(7);
    }
    // Verify that the only ABI is x86.
    ImmutableSet<Abi> abiTargetings = moduleSplits.stream().map(ModuleSplit::getApkTargeting).map(ApkTargeting::getAbiTargeting).map(AbiTargeting::getValueList).flatMap(List::stream).collect(toImmutableSet());
    assertThat(abiTargetings).containsExactly(toAbi(X86));
    // And ABI has no alternatives.
    ImmutableSet<Abi> abiAlternatives = moduleSplits.stream().map(ModuleSplit::getApkTargeting).map(ApkTargeting::getAbiTargeting).map(AbiTargeting::getAlternativesList).flatMap(List::stream).collect(toImmutableSet());
    assertThat(abiAlternatives).isEmpty();
    assertThat(moduleSplits.stream().map(ModuleSplit::getSplitType).collect(toImmutableSet())).containsExactly(standaloneSplitType);
}
Also used : TargetingUtils.apkAbiTargeting(com.android.tools.build.bundletool.testing.TargetingUtils.apkAbiTargeting) AbiTargeting(com.android.bundle.Targeting.AbiTargeting) BundleModuleBuilder(com.android.tools.build.bundletool.testing.BundleModuleBuilder) ModuleSplit(com.android.tools.build.bundletool.model.ModuleSplit) TargetingUtils.toAbi(com.android.tools.build.bundletool.testing.TargetingUtils.toAbi) Abi(com.android.bundle.Targeting.Abi) ResourceTableBuilder(com.android.tools.build.bundletool.testing.ResourceTableBuilder) ApkOptimizations(com.android.tools.build.bundletool.optimizations.ApkOptimizations) Optimizations(com.android.bundle.Config.Optimizations) BundleModule(com.android.tools.build.bundletool.model.BundleModule) Test(org.junit.Test) Theory(org.junit.experimental.theories.Theory)

Example 3 with AbiTargeting

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

the class AbstractSizeAggregator method getSizesPerConfiguration.

protected ConfigurationSizes getSizesPerConfiguration(ImmutableSet<SdkVersionTargeting> sdkTargetingOptions, ImmutableSet<AbiTargeting> abiTargetingOptions, ImmutableSet<LanguageTargeting> languageTargetingOptions, ImmutableSet<ScreenDensityTargeting> screenDensityTargetingOptions, ImmutableSet<TextureCompressionFormatTargeting> textureCompressionFormatTargetingOptions, ImmutableSet<DeviceTierTargeting> deviceTierTargetingOptions) {
    Map<SizeConfiguration, Long> minSizeByConfiguration = new HashMap<>();
    Map<SizeConfiguration, Long> maxSizeByConfiguration = new HashMap<>();
    for (SdkVersionTargeting sdkVersionTargeting : sdkTargetingOptions) {
        for (AbiTargeting abiTargeting : abiTargetingOptions) {
            for (ScreenDensityTargeting screenDensityTargeting : screenDensityTargetingOptions) {
                for (LanguageTargeting languageTargeting : languageTargetingOptions) {
                    for (TextureCompressionFormatTargeting textureCompressionFormatTargeting : textureCompressionFormatTargetingOptions) {
                        for (DeviceTierTargeting deviceTierTargeting : deviceTierTargetingOptions) {
                            SizeConfiguration configuration = mergeWithDeviceSpec(getSizeConfiguration(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting), getSizeRequest.getDeviceSpec());
                            long compressedSize = getCompressedSize(getMatchingApks(sdkVersionTargeting, abiTargeting, screenDensityTargeting, languageTargeting, textureCompressionFormatTargeting, deviceTierTargeting));
                            minSizeByConfiguration.merge(configuration, compressedSize, Math::min);
                            maxSizeByConfiguration.merge(configuration, compressedSize, Math::max);
                        }
                    }
                }
            }
        }
    }
    return ConfigurationSizes.create(/* minSizeConfigurationMap= */
    ImmutableMap.copyOf(minSizeByConfiguration), /* maxSizeConfigurationMap= */
    ImmutableMap.copyOf(maxSizeByConfiguration));
}
Also used : LanguageTargeting(com.android.bundle.Targeting.LanguageTargeting) DeviceTierTargeting(com.android.bundle.Targeting.DeviceTierTargeting) HashMap(java.util.HashMap) AbiTargeting(com.android.bundle.Targeting.AbiTargeting) SdkVersionTargeting(com.android.bundle.Targeting.SdkVersionTargeting) TextureCompressionFormatTargeting(com.android.bundle.Targeting.TextureCompressionFormatTargeting) SizeConfiguration(com.android.tools.build.bundletool.model.SizeConfiguration) ScreenDensityTargeting(com.android.bundle.Targeting.ScreenDensityTargeting)

Example 4 with AbiTargeting

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

the class ProtoFuzzerTest method randomProtoMessage_repeatedMessageFieldPopulated.

@Test
public void randomProtoMessage_repeatedMessageFieldPopulated() {
    AbiTargeting randomProto = ProtoFuzzer.randomProtoMessage(AbiTargeting.class);
    // At least some values populated.
    assertThat(randomProto).isNotEqualTo(AbiTargeting.getDefaultInstance());
    // Not all random values are the same.
    assertThat(ImmutableSet.copyOf(randomProto.getValueList()).size()).isGreaterThan(1);
    assertThat(ImmutableSet.copyOf(randomProto.getAlternativesList()).size()).isGreaterThan(1);
}
Also used : AbiTargeting(com.android.bundle.Targeting.AbiTargeting) Test(org.junit.Test)

Example 5 with AbiTargeting

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

the class BuildApksPreprocessingTest method renderscript32Bit_64BitStandaloneAndSplitApksFilteredOut.

@Test
public void renderscript32Bit_64BitStandaloneAndSplitApksFilteredOut() throws Exception {
    AppBundle appBundle = new AppBundleBuilder().addModule("base", module -> module.addFile("dex/classes.dex").addFile("assets/script.bc").addFile("lib/armeabi-v7a/libfoo.so").addFile("lib/arm64-v8a/libfoo.so").setManifest(androidManifest("com.test.app", withMinSdkVersion(14))).setNativeConfig(nativeLibraries(targetedNativeDirectory("lib/armeabi-v7a", nativeDirectoryTargeting(ARMEABI_V7A)), targetedNativeDirectory("lib/arm64-v8a", nativeDirectoryTargeting(ARM64_V8A))))).setBundleConfig(BundleConfigBuilder.create().setUncompressNativeLibraries(false).build()).build();
    new AppBundleSerializer().writeToDisk(appBundle, bundlePath);
    BuildApksCommand command = BuildApksCommand.builder().setBundlePath(bundlePath).setOutputFile(outputFilePath).build();
    command.execute();
    BuildApksResult result;
    try (ZipFile apkSetFile = new ZipFile(outputFilePath.toFile())) {
        result = extractTocFromApkSetFile(apkSetFile, outputDir);
    }
    assertThat(standaloneApkVariants(result)).hasSize(1);
    assertThat(standaloneApkVariants(result).get(0).getTargeting().getAbiTargeting()).isEqualTo(abiTargeting(ARMEABI_V7A));
    assertThat(splitApkVariants(result)).hasSize(1);
    ImmutableSet<AbiTargeting> abiTargetings = splitApkVariants(result).get(0).getApkSetList().stream().map(ApkSet::getApkDescriptionList).flatMap(list -> list.stream().map(ApkDescription::getTargeting)).map(ApkTargeting::getAbiTargeting).collect(toImmutableSet());
    assertThat(abiTargetings).containsExactly(AbiTargeting.getDefaultInstance(), abiTargeting(ARMEABI_V7A));
}
Also used : AppBundle(com.android.tools.build.bundletool.model.AppBundle) ZipFile(java.util.zip.ZipFile) BuildApksResult(com.android.bundle.Commands.BuildApksResult) AbiTargeting(com.android.bundle.Targeting.AbiTargeting) AppBundleBuilder(com.android.tools.build.bundletool.testing.AppBundleBuilder) AppBundleSerializer(com.android.tools.build.bundletool.io.AppBundleSerializer) Test(org.junit.Test)

Aggregations

AbiTargeting (com.android.bundle.Targeting.AbiTargeting)5 Test (org.junit.Test)3 LanguageTargeting (com.android.bundle.Targeting.LanguageTargeting)2 TextureCompressionFormatTargeting (com.android.bundle.Targeting.TextureCompressionFormatTargeting)2 BuildApksResult (com.android.bundle.Commands.BuildApksResult)1 Optimizations (com.android.bundle.Config.Optimizations)1 Abi (com.android.bundle.Targeting.Abi)1 DeviceTierTargeting (com.android.bundle.Targeting.DeviceTierTargeting)1 MultiAbi (com.android.bundle.Targeting.MultiAbi)1 MultiAbiTargeting (com.android.bundle.Targeting.MultiAbiTargeting)1 Sanitizer (com.android.bundle.Targeting.Sanitizer)1 SanitizerTargeting (com.android.bundle.Targeting.SanitizerTargeting)1 ScreenDensityTargeting (com.android.bundle.Targeting.ScreenDensityTargeting)1 SdkVersionTargeting (com.android.bundle.Targeting.SdkVersionTargeting)1 AppBundleSerializer (com.android.tools.build.bundletool.io.AppBundleSerializer)1 AppBundle (com.android.tools.build.bundletool.model.AppBundle)1 BundleModule (com.android.tools.build.bundletool.model.BundleModule)1 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)1 SizeConfiguration (com.android.tools.build.bundletool.model.SizeConfiguration)1 ApkOptimizations (com.android.tools.build.bundletool.optimizations.ApkOptimizations)1