in analyzer/src/main/java/com/android/tools/sizereduction/analyzer/suggesters/proguard/ProguardSuggester.java [71:123]
public ImmutableList<Suggestion> processBundle(
BundleContext context, AppBundle bundle, ZipFile bundleZip) {
// Some old bundles contain multidex code in a way not compatible with the new AppBundle
// representation, so the extraction of ZIP entries results in null pointers. Hence, entries are
// wrapped in optionals to precisely capture the nulls.
ImmutableList<Optional<ZipEntry>> dexFileEntries =
bundle.getModules().values().stream()
.flatMap(
module ->
module
.findEntriesUnderPath(BundleModule.DEX_DIRECTORY)
.map(ModuleEntry::getPath)
.map(ZipPath.create(module.getName().toString())::resolve))
.map(ZipPath::toString)
.map(bundleZip::getEntry)
.map(Optional::ofNullable)
.collect(toImmutableList());
OptionalLong totalDex =
dexFileEntries.stream().anyMatch(not(Optional::isPresent))
? OptionalLong.empty()
: OptionalLong.of(
dexFileEntries.stream().map(Optional::get).mapToLong(ZipEntry::getSize).sum());
ZipEntry proguardEntry = bundleZip.getEntry(PROGUARD_MAP);
if (proguardEntry == null) {
return ImmutableList.of(
Suggestion.create(
IssueType.PROGUARD_NO_MAP,
Category.PROGUARD,
totalDexPayload(totalDex),
NO_MAP_SUGGESTION_MESSAGE,
/* estimatedBytesSaved= */ null,
/* autoFix= */ null));
}
// Deobfuscation map present.
if (proguardEntry.getSize() == 0) {
// Empty deobfuscation map.
return ImmutableList.of(
Suggestion.create(
IssueType.PROGUARD_EMPTY_MAP,
Category.PROGUARD,
totalDexPayload(totalDex),
EMPTY_MAP_SUGGESTION_MESSAGE,
/* estimatedBytesSaved= */ null,
/* autoFix= */ null));
}
// Everything is fine with the map, no suggestions.
return ImmutableList.of();
}