We are working on enabling the collapse names optimization of aapt2 that removes the resource names from the Resource Table as an app size optimization. However, once enabled, we ran into issues loading resources.
One requirement of removing resource names from the Resource Table is ensuring that resources are not referenced by resource name when loaded. If they are referenced by resource name, they must be explicitly kept with keep rules. (ref).
ResourceLoader is using the android.resource://<package_name>/<resource_type>/<resource_name> content URI to resolve Drawable resources, which is incompatible with collapse names optimization.
Fortunately, the ContentResolver for resources has another URI scheme that enables loading resources without referencing the name: android.resource://<package_name>/<resource_id>, which can be used instead (ref).
Description
We are working on enabling the collapse names optimization of
aapt2
that removes the resource names from the Resource Table as an app size optimization. However, once enabled, we ran into issues loading resources.One requirement of removing resource names from the Resource Table is ensuring that resources are not referenced by resource name when loaded. If they are referenced by resource name, they must be explicitly kept with keep rules. (ref).
ResourceLoader is using the
android.resource://<package_name>/<resource_type>/<resource_name>
content URI to resolve Drawable resources, which is incompatible with collapse names optimization.Fortunately, the ContentResolver for resources has another URI scheme that enables loading resources without referencing the name:
android.resource://<package_name>/<resource_id>
, which can be used instead (ref).