Skip to content

Package HEIC and HEIF image assets as Android raw resources - #60372

Draft
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/android-heic-raw-resources
Draft

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/android-heic-raw-resources

Conversation

@ide

@ide ide commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary:

drawableFileTypes lists heic and heif, so the bundle command copies such an asset into a drawable-* resource folder. The Android Gradle plugin validates the files in those folders (FileResourceNameValidator) and accepts only .xml, .png, .9.png, .gif, .jpeg, .jpg, .bmp, .webp and .avif. Any other file fails resource merging with "The file name must end with .xml or .png", so a release build of an app that requires a HEIC image fails.

This change removes both types from drawableFileTypes, so the assets go to raw, where any file is accepted. An image is passed to native code by resource name, and ResourceDrawableIdHelper looked the name up only among drawables. getResourceDrawableUri, which turns an image source's name into the res: URI that Fresco loads, now looks among the raw resources when no drawable has the name, so the image still resolves. A drawable keeps precedence over a raw resource with the same name.

The fallback is limited to that method. getResourceDrawableId and getResourceDrawable still resolve drawables only, because their callers (defaultSource and loadingIndicatorSource on Image, inlineImageLeft on TextInput, and ImageLoaderModule) load the id as a drawable, and a raw resource of the same name, such as a JSON file, would throw Resources.NotFoundException there. A HEIC image therefore works as an image source but not in those props.

Density variants of a raw asset are not kept: photo@2x.heic and photo@3x.heic are both written to raw/photo.heic, as for other raw asset types.

The fallback also applies to other image types that are bundled as raw resources because they are not in drawableFileTypes, such as BMP.

ktx stays in the list. AGP rejects it in the same way, but nothing in the open source image pipeline decodes it, and I left it alone.

Changelog:

[ANDROID] [FIXED] - Package HEIC and HEIF image assets as raw resources so that release builds accept them

Test Plan:

AndroidPathUtils-test.js checks that heic and heif assets go to raw.

yarn jest packages/asset-utils packages/community-cli-plugin/src/commands/bundle
  • With the change to AndroidPathUtils.js reverted: 2 tests fail (Expected: "raw", Received: "drawable-mdpi").
  • With the change: 5 suites, 27 tests pass.

Also run: yarn eslint --max-warnings 0 and prettier --check on the two changed JS files (clean), yarn flow-check (0 errors), ktfmt --dry-run --set-exit-if-changed on the two changed Kotlin files (clean), git diff --check (clean).

The accepted extensions come from javap on com.android.utils.SdkUtils and com.android.ide.common.resources.FileResourceNameValidator in the common and sdk-common 32.2.1 jars, which AGP 9.2.1 uses.

The Kotlin tests, run on this base (2026-11-28):

./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests com.facebook.react.views.imagehelper.ResourceDrawableIdHelperTest -Preact.internal.useHermesStable=true --console=plain
  • With ResourceDrawableIdHelper.kt from main and the new tests kept: 8 tests, 1 failed (uriFallsBackToRawResourceForNameWithoutADrawable, which gets an empty URI).
  • On this branch: all 8 pass, including drawableIdIgnoresRawResources, which guards the callers that load drawables.

Not run: a release build of an app with a HEIC asset, and showing the image on a device from a raw resource.

🤖 Generated with Claude Code

The bundle command copies a HEIC or HEIF asset into a `drawable-*`
resource folder. The Android Gradle plugin accepts only XML, PNG, GIF,
JPEG, BMP, WebP and AVIF files there, and fails the build on any other
file with "The file name must end with .xml or .png", so a release
build of an app that requires a HEIC image fails.

Remove both types from `drawableFileTypes` so the assets go to `raw`,
where any file is accepted. So that the image still resolves,
`ResourceDrawableIdHelper.getResourceDrawableUri`, which turns an image
source's resource name into a `res:` URI for Fresco, looks the name up
among the raw resources when no drawable has it. A drawable keeps
precedence over a raw resource with the same name.

`getResourceDrawableId` and `getResourceDrawable` still resolve
drawables only: their callers load the id as a drawable, which a raw
resource is not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 28, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant