Null out names of unused resources in optimized shrinking
These are not needed when the resource can no longer be looked up.
Bug: 287398085
Change-Id: Ibb13cb1dbe6da8bc90f5aae374bcb469fbc2e0c2
diff --git a/src/resourceshrinker/java/com/android/build/shrinker/ResourceTableUtil.kt b/src/resourceshrinker/java/com/android/build/shrinker/ResourceTableUtil.kt
index 4327997..88bb5e4 100644
--- a/src/resourceshrinker/java/com/android/build/shrinker/ResourceTableUtil.kt
+++ b/src/resourceshrinker/java/com/android/build/shrinker/ResourceTableUtil.kt
@@ -33,20 +33,28 @@
internal fun Resources.ResourceTable.nullOutEntriesWithIds(ids: List<Int>)
: Resources.ResourceTable {
+ return nullOutEntriesWithIds(ids, false)
+}
+
+internal fun Resources.ResourceTable.nullOutEntriesWithIds(
+ ids: List<Int>, pruneResourceNames: Boolean): Resources.ResourceTable {
if (ids.isEmpty()) {
return this
}
val packageMappings = calculatePackageMappings(ids)
val tableBuilder = this.toBuilder()
- tableBuilder.packageBuilderList.forEach{
+ tableBuilder.packageBuilderList.forEach {
val typeMappings = packageMappings[it.packageId.id]
if (typeMappings != null) {
- it.typeBuilderList.forEach { type->
+ it.typeBuilderList.forEach { type ->
val entryList = typeMappings[type.typeId.id]
if (entryList != null) {
type.entryBuilderList.forEach { entry ->
if (entryList.contains(entry.entryId.id)) {
entry.clearConfigValue()
+ if (pruneResourceNames) {
+ entry.clearName();
+ }
if (entry.hasOverlayableItem()) {
entry.clearOverlayableItem()
}