Search in sources :

Example 1 with Optimizations

use of com.android.bundle.Config.Optimizations in project bundletool by google.

the class OptimizationsMerger method mergeWithDefaults.

/**
 * Merges the optimizations instructions supplied by the developer (in the BundleConfig), the
 * defaults set by BundleTool and the values provided in the command.
 *
 * <p>If {@code optimizationsOverride} is not empty, we only apply these optimizations. Otherwise,
 * we use the default optimizations merged with the overrides specified in the BundleConfig.
 */
// Optimization flags will go away soon!
@Deprecated
public ApkOptimizations mergeWithDefaults(BundleConfig bundleConfig, ImmutableSet<OptimizationDimension> optimizationsOverride) {
    // Default optimizations performed on APKs if the developer doesn't specify any preferences.
    String buildVersionString = bundleConfig.getBundletool().getVersion();
    Version bundleToolBuildVersion = buildVersionString.isEmpty() ? BundleToolVersion.getCurrentVersion() : Version.of(buildVersionString);
    ApkOptimizations defaultOptimizations = ApkOptimizations.getDefaultOptimizationsForVersion(bundleToolBuildVersion);
    // Preferences specified by the developer.
    Optimizations requestedOptimizations = bundleConfig.getOptimizations();
    // Until we get rid of OptimizationsOverride flag, it takes precedence over anything else.
    ImmutableSet<OptimizationDimension> splitDimensions = getEffectiveSplitDimensions(defaultOptimizations, requestedOptimizations, optimizationsOverride);
    ImmutableSet<OptimizationDimension> standaloneDimensions = getEffectiveStandaloneDimensions(defaultOptimizations, requestedOptimizations, optimizationsOverride);
    // If developer sets UncompressNativeLibraries use that, otherwise use the default value.
    boolean uncompressNativeLibraries = requestedOptimizations.hasUncompressNativeLibraries() ? requestedOptimizations.getUncompressNativeLibraries().getEnabled() : defaultOptimizations.getUncompressNativeLibraries();
    boolean uncompressDexFiles = requestedOptimizations.hasUncompressDexFiles() ? requestedOptimizations.getUncompressDexFiles().getEnabled() : defaultOptimizations.getUncompressDexFiles();
    ImmutableMap<OptimizationDimension, SuffixStripping> suffixStrippings = getSuffixStrippings(bundleConfig.getOptimizations().getSplitsConfig().getSplitDimensionList());
    return ApkOptimizations.builder().setSplitDimensions(splitDimensions).setUncompressNativeLibraries(uncompressNativeLibraries).setUncompressDexFiles(uncompressDexFiles).setStandaloneDimensions(standaloneDimensions).setSuffixStrippings(suffixStrippings).build();
}
Also used : BundleToolVersion(com.android.tools.build.bundletool.model.version.BundleToolVersion) Version(com.android.tools.build.bundletool.model.version.Version) OptimizationDimension(com.android.tools.build.bundletool.model.OptimizationDimension) SuffixStripping(com.android.bundle.Config.SuffixStripping) Optimizations(com.android.bundle.Config.Optimizations)

Example 2 with Optimizations

use of com.android.bundle.Config.Optimizations in project bundletool by google.

the class TextureCompressionFormatParityValidator method validateBundle.

@Override
public void validateBundle(AppBundle bundle) {
    BundleConfig bundleConfig = bundle.getBundleConfig();
    Optimizations optimizations = bundleConfig.getOptimizations();
    List<SplitDimension> splitDimensions = optimizations.getSplitsConfig().getSplitDimensionList();
    Optional<String> tcfDefaultSuffix = splitDimensions.stream().filter(dimension -> dimension.getValue().equals(Value.TEXTURE_COMPRESSION_FORMAT)).map(dimension -> dimension.getSuffixStripping().getDefaultSuffix()).collect(toOptional());
    if (tcfDefaultSuffix.isPresent()) {
        // Get the default texture compression format targeting, or an empty optional if fallback
        // must be used.
        Optional<TextureCompressionFormatTargeting> defaultTextureCompressionFormat = Optional.ofNullable(TextureCompressionUtils.TEXTURE_TO_TARGETING.get(tcfDefaultSuffix.get()));
        validateFormatSupportedByAllModules(bundle, defaultTextureCompressionFormat);
    }
}
Also used : MoreCollectors.toOptional(com.google.common.collect.MoreCollectors.toOptional) ImmutableSet(com.google.common.collect.ImmutableSet) Value(com.android.bundle.Config.SplitDimension.Value) Optimizations(com.android.bundle.Config.Optimizations) InvalidBundleException(com.android.tools.build.bundletool.model.exceptions.InvalidBundleException) TargetedDirectory(com.android.tools.build.bundletool.model.targeting.TargetedDirectory) TargetingDimension(com.android.tools.build.bundletool.model.targeting.TargetingDimension) List(java.util.List) TextureCompressionUtils(com.android.tools.build.bundletool.model.utils.TextureCompressionUtils) ImmutableList(com.google.common.collect.ImmutableList) BundleConfig(com.android.bundle.Config.BundleConfig) SplitDimension(com.android.bundle.Config.SplitDimension) AssetsDirectoryTargeting(com.android.bundle.Targeting.AssetsDirectoryTargeting) TextureCompressionFormatTargeting(com.android.bundle.Targeting.TextureCompressionFormatTargeting) AutoValue(com.google.auto.value.AutoValue) Optional(java.util.Optional) TargetingUtils.extractTextureCompressionFormats(com.android.tools.build.bundletool.model.targeting.TargetingUtils.extractTextureCompressionFormats) TextureCompressionFormatAlias(com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias) TargetingUtils.extractAssetsTargetedDirectories(com.android.tools.build.bundletool.model.targeting.TargetingUtils.extractAssetsTargetedDirectories) AppBundle(com.android.tools.build.bundletool.model.AppBundle) BundleModule(com.android.tools.build.bundletool.model.BundleModule) BundleConfig(com.android.bundle.Config.BundleConfig) SplitDimension(com.android.bundle.Config.SplitDimension) TextureCompressionFormatTargeting(com.android.bundle.Targeting.TextureCompressionFormatTargeting) Optimizations(com.android.bundle.Config.Optimizations)

Example 3 with Optimizations

use of com.android.bundle.Config.Optimizations 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)

Aggregations

Optimizations (com.android.bundle.Config.Optimizations)3 BundleModule (com.android.tools.build.bundletool.model.BundleModule)2 BundleConfig (com.android.bundle.Config.BundleConfig)1 SplitDimension (com.android.bundle.Config.SplitDimension)1 Value (com.android.bundle.Config.SplitDimension.Value)1 SuffixStripping (com.android.bundle.Config.SuffixStripping)1 Abi (com.android.bundle.Targeting.Abi)1 AbiTargeting (com.android.bundle.Targeting.AbiTargeting)1 AssetsDirectoryTargeting (com.android.bundle.Targeting.AssetsDirectoryTargeting)1 TextureCompressionFormatAlias (com.android.bundle.Targeting.TextureCompressionFormat.TextureCompressionFormatAlias)1 TextureCompressionFormatTargeting (com.android.bundle.Targeting.TextureCompressionFormatTargeting)1 AppBundle (com.android.tools.build.bundletool.model.AppBundle)1 ModuleSplit (com.android.tools.build.bundletool.model.ModuleSplit)1 OptimizationDimension (com.android.tools.build.bundletool.model.OptimizationDimension)1 InvalidBundleException (com.android.tools.build.bundletool.model.exceptions.InvalidBundleException)1 TargetedDirectory (com.android.tools.build.bundletool.model.targeting.TargetedDirectory)1 TargetingDimension (com.android.tools.build.bundletool.model.targeting.TargetingDimension)1 TargetingUtils.extractAssetsTargetedDirectories (com.android.tools.build.bundletool.model.targeting.TargetingUtils.extractAssetsTargetedDirectories)1 TargetingUtils.extractTextureCompressionFormats (com.android.tools.build.bundletool.model.targeting.TargetingUtils.extractTextureCompressionFormats)1 TextureCompressionUtils (com.android.tools.build.bundletool.model.utils.TextureCompressionUtils)1