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();
}
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);
}
}
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);
}
Aggregations