Skip to content

Resolve Android resource references (@drawable/name) in memory footprint - #115

Open
mihais wants to merge 1 commit into
google:mainfrom
mihais:fix-android-resource-references
Open

mihais wants to merge 1 commit into
google:mainfrom
mihais:fix-android-resource-references

Conversation

@mihais

@mihais mihais commented Oct 2, 2026

Copy link
Copy Markdown

Watch faces may reference drawables using the Android resource reference syntax, e.g. resource="@drawable/name", instead of the bare resource name. The Watch Face Format runtime resolves both forms to the same drawable, but the memory footprint validator looked up the raw attribute value in a resource map keyed by bare name and failed with:

Asset @drawable/name was not found in the watch face package

even though the drawable is present in the APK.

Change

  • Add WatchFaceDocuments.getResourceReference / normalizeResourceReference, which strip the @type/ (or @package:type/) prefix from a reference. Expressions ([...]), bare names and empty values are returned unchanged.
  • Use it for the resource and thumbnail attributes in WatchFaceResourceCollector, and for resource in OptimizationEstimator, so both the footprint evaluation and the optimization estimate find the referenced drawable.

Testing

  • New WatchFaceDocumentsTest for the normalization.
  • New WatchFaceResourceCollectorTest#collectResources_normalizesAndroidResourceReferences.
  • New ResourceMemoryEvaluatorTest layout case (AndroidResourceReferences.xml, a copy of ImageHiddenInActive.xml using @drawable/ references) that expects the same footprint as the bare-name layout.
  • ./gradlew spotlessCheck memory-footprint:jar memory-footprint:test passes (135 tests, including GoldenTest). Without the fix, the new reference tests fail with the error above.
  • Verified on three real watch faces that use <Image resource="@drawable/...">: they fail on main and pass with this change, with the same reported footprint as when the references are rewritten to bare names.

Watch faces may reference drawables using the Android resource reference
syntax, e.g. resource="@drawable/name", instead of the bare resource
name. The Watch Face Format runtime resolves both forms to the same
drawable, but the memory footprint validator looked up the raw attribute
value in a resource map keyed by bare name and failed with
"Asset @drawable/name was not found in the watch face package".

Normalize `resource` and `thumbnail` references by dropping the
`@type/` (or `@package:type/`) prefix before looking them up, both in
the resource collector and in the optimization estimator. Expressions
and bare names are left unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant