Repository navigation
Ship ExifInterface so a HEIC image does not crash Android - #60371
Merged
Merged
Conversation
Fresco 3.9.0 reads a HEIF image's EXIF orientation with `androidx.exifinterface.media.ExifInterface` (`HeifExifUtil.getOrientation`), but no Fresco artifact declares that dependency and neither does ReactAndroid. An app that does not depend on ExifInterface some other way throws `NoClassDefFoundError` when it decodes its first HEIC or HEIF image. Fresco catches only `IOException` there, and the error is thrown on a background thread, so it ends the process. Make `androidx.exifinterface:exifinterface` 1.4.2 a dependency of ReactAndroid so that every app that gets Fresco through React Native also gets the class. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ide
marked this pull request as ready for review
November 29, 2026 12:02
chrfalch
reviewed
Nov 29, 2026
chrfalch
left a comment
Collaborator
There was a problem hiding this comment.
Commenting rather than approving since this is still a draft.
Dependency check (done, so the next reviewer can skip it). I compared the resolved releaseRuntimeClasspath of :packages:react-native:ReactAndroid on this PR (c474484) and on main (35f49a3), with Gradle 9.4.1, AGP 9.2.1 and JDK 17:
./gradlew :packages:react-native:ReactAndroid:dependencies --configuration releaseRuntimeClasspath
./gradlew :packages:react-native:ReactAndroid:dependencyInsight --configuration releaseRuntimeClasspath --dependency androidx.annotation
- The only difference is the new
androidx.exifinterface:exifinterface:1.4.2. No other module is added and no resolved version changes. androidx.annotationresolves to 1.9.1 on both (requested byandroidx.window:window-core-android:1.5.1). exifinterface asks for 1.8.1, so it doesn't move anything. The1.6.0inlibs.versions.tomlis already outvoted onmain.org.jspecify:jspecify, which the exifinterface POM declares, is compile-scope only and doesn't appear on the runtime classpath.
Test request. A small Robolectric test would pin this down, for example Class.forName("androidx.exifinterface.media.ExifInterface"), or calling Fresco's HEIF orientation path on a stream. It fails on main with the same NoClassDefFoundError/ClassNotFoundException and passes here, so the dependency can't be dropped by accident later.
cortinico
approved these changes
Nov 30, 2026
Contributor
|
Thanks for fixing this @ide |
Contributor
Author
meta-codesync Bot
pushed a commit
that referenced
this pull request
Dec 1, 2026
## Summary: `drawableFileTypes` lists `heic` and `heif`, so the bundle command copies such an asset into a `drawable-*` folder. The Android Gradle plugin (`FileResourceNameValidator`) accepts only `.xml`, `.png`, `.9.png`, `.gif`, `.jpeg`, `.jpg`, `.bmp`, `.webp` and `.avif` files in those folders, and fails resource merging on any other file with "The file name must end with .xml or .png". A release build of an app that requires a HEIC image therefore fails. This change removes both types from `drawableFileTypes`, so these assets go to `raw`, which accepts any file. `ResourceDrawableIdHelper.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. A drawable keeps precedence. The fallback matches a raw resource by name alone, whatever its type. In an app that bundles `intro.mp3`, an `Image` whose source names `intro` used to stay blank; Fresco now fails to decode the file and the `Image` calls `onError`. `getResourceDrawableUri` is public, so other callers get the fallback too. A raw HEIC may be stored compressed in the APK: `.heic` and `.heif` are not among the extensions AAPT2 leaves uncompressed (`.jpg`, `.png`, `.webp` and others; [`Link.cpp`](https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/tools/aapt2/cmd/Link.cpp)), so AAPT2 deflates such a file when that makes it smaller. Fresco reads it either way. `LocalResourceFetchProducer` reads the bytes with `Resources.openRawResource`, which decompresses, and uses [`openRawResourceFd`](https://developer.android.com/reference/android/content/res/Resources#openRawResourceFd(int)), which works only on uncompressed data, just to learn the length: it catches the `Resources.NotFoundException` and reads the stream to its end. Decoding a HEIC also needs ExifInterface on the classpath, which #60371 added. `ResourceDrawableIdHelper` now guards its maps with one monitor, the class. On `main`, `clear()` locks the class (`@Synchronized` on a `@JvmStatic` function) and the lookup locks the object, so the two do not exclude each other. Limitations: - `getResourceDrawableId` and `getResourceDrawable` still resolve drawables only: their callers (`defaultSource` and `loadingIndicatorSource` on `Image`, `inlineImageLeft` on `TextInput`, and `ImageLoaderModule`) load the id as a drawable, and a raw resource with the same name, such as a JSON file, would throw `Resources.NotFoundException`. A HEIC image 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. - `ktx` stays in the list. AGP rejects it in the same way, but nothing in the open source image pipeline decodes it. ## Changelog: [ANDROID] [FIXED] - Package HEIC and HEIF image assets as raw resources so that release builds accept them ## Test Plan: ```sh yarn jest packages/asset-utils packages/community-cli-plugin/src/commands/bundle ``` New `AndroidPathUtils-test.js` cases check that `heic` and `heif` assets go to `raw`; on `main` they fail (`Expected: "raw"`, `Received: "drawable-mdpi"`). ```sh ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests com.facebook.react.views.imagehelper.ResourceDrawableIdHelperTest -Preact.internal.useHermesStable=true --console=plain ``` New tests: `uriFallsBackToRawResourceForNameWithoutADrawable` (fails on `main` with an empty URI), `uriPrefersDrawableOverRawResourceWithTheSameName`, and `drawableIdIgnoresRawResources`. The compression behavior comes from the sources and from AAPT2 9.2.1 itself: `aapt2 link` on a `res/raw` folder stores a compressible `.heic` file deflated and a `.jpg` with the same bytes uncompressed, and `javap -p -c` on `LocalResourceFetchProducer` in `imagepipeline-3.9.0` shows the calls and the exception table described above. The accepted extensions come from `javap` on `SdkUtils` and `FileResourceNameValidator` in the `common` and `sdk-common` 32.2.1 jars, which AGP 9.2.1 uses. ESLint, Prettier, `yarn flow-check` and ktfmt are clean. Not run: a release build of an app with a HEIC asset, and showing the image from a raw resource on a device. Differential Revision: D135070431 Pull Request resolved: #60372
meta-codesync Bot
pushed a commit
that referenced
this pull request
Dec 1, 2026
## Summary: #60371 made ReactAndroid depend on `androidx.exifinterface`, which Fresco 3.9.0 uses to read a HEIF image's EXIF orientation but does not declare. No test failed if that dependency was removed. The new `HeifExifOrientationTest` calls Fresco's `HeifExifUtil.getOrientation`, the method that crashed, on a stream that holds an EXIF orientation tag, and expects that orientation back. It goes through Fresco instead of loading the class by name, so it checks what an app needs: if a later Fresco stops using ExifInterface, the test passes without the dependency. The stream is a JPEG with no image data, the smallest file ExifInterface reads: `HeifExifUtil` passes the stream to `ExifInterface` without checking its format, and parsing a real HEIF goes through `MediaMetadataRetriever`, which Robolectric only stubs. ## Changelog: [INTERNAL] [ADDED] - Test that ReactAndroid provides the ExifInterface class Fresco uses for HEIF images ## Test Plan: ```sh ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests com.facebook.react.modules.fresco.HeifExifOrientationTest -Preact.internal.useHermesStable=true --console=plain ``` The test passes. With `implementation(libs.androidx.exifinterface)` removed from `ReactAndroid/build.gradle.kts` it fails as an app did before #60371: ``` java.lang.NoClassDefFoundError: androidx/exifinterface/media/ExifInterface at com.facebook.imageutils.HeifExifUtil.getOrientation(HeifExifUtil.kt:31) ``` ktfmt is clean. Differential Revision: D135308452 Pull Request resolved: #60420
ide
added a commit
to expo/react-native
that referenced
this pull request
Dec 4, 2026
Why === RN Tester's Android Release build failed with "Duplicate resources": its color gallery bundles `color/pq.avif` and `color/pq.heic`, and both became the raw resource `js_assets_color_pq`. Android ignores the extension when it assigns a resource ID, and raw resources of every format share one folder. Frontier named a raw resource with its format to avoid this, but upstream's version of the same change (react#60371) does not, and the rebase dropped frontier's copy as merged. How === `getAndroidResourceIdentifier` appends the format to the name of a raw resource (`color_pq_heic` beside `color_pq_avif`), and leaves drawable names unchanged. The bundler writes the resource under that name and `AssetSourceResolver` looks it up by the same name, since both call this function. Test Plan ========= `yarn jest packages/asset-utils packages/community-cli-plugin/src/commands/bundle packages/react-native/Libraries/Image` passes, including a test that two raw assets differing only in format get different identifiers. `./gradlew :packages:rn-tester:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds and packages `js_assets_color_pq_avif` and `js_assets_color_pq_heic`, and the app launches on an Android 16 emulator.
ide
added a commit
to expo/react-native
that referenced
this pull request
Dec 5, 2026
Why === RN Tester's Android Release build failed with "Duplicate resources": its color gallery bundles `color/pq.avif` and `color/pq.heic`, and both became the raw resource `js_assets_color_pq`. Android ignores the extension when it assigns a resource ID, and raw resources of every format share one folder. Frontier named a raw resource with its format to avoid this, but upstream's version of the same change (react#60371) does not, and the rebase dropped frontier's copy as merged. How === `getAndroidResourceIdentifier` appends the format to the name of a raw resource (`color_pq_heic` beside `color_pq_avif`), and leaves drawable names unchanged. The bundler writes the resource under that name and `AssetSourceResolver` looks it up by the same name, since both call this function. Test Plan ========= `yarn jest packages/asset-utils packages/community-cli-plugin/src/commands/bundle packages/react-native/Libraries/Image` passes, including a test that two raw assets differing only in format get different identifiers. `./gradlew :packages:rn-tester:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds and packages `js_assets_color_pq_avif` and `js_assets_color_pq_heic`, and the app launches on an Android 16 emulator.
ide
added a commit
to expo/react-native
that referenced
this pull request
Dec 5, 2026
Why === RN Tester's Android Release build failed with "Duplicate resources": its color gallery bundles `color/pq.avif` and `color/pq.heic`, and both became the raw resource `js_assets_color_pq`. Android ignores the extension when it assigns a resource ID, and raw resources of every format share one folder. Frontier named a raw resource with its format to avoid this, but upstream's version of the same change (react#60371) does not, and the rebase dropped frontier's copy as merged. How === `getAndroidResourceIdentifier` appends the format to the name of a raw resource (`color_pq_heic` beside `color_pq_avif`), and leaves drawable names unchanged. The bundler writes the resource under that name and `AssetSourceResolver` looks it up by the same name, since both call this function. Test Plan ========= `yarn jest packages/asset-utils packages/community-cli-plugin/src/commands/bundle packages/react-native/Libraries/Image` passes, including a test that two raw assets differing only in format get different identifiers. `./gradlew :packages:rn-tester:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds and packages `js_assets_color_pq_avif` and `js_assets_color_pq_heic`, and the app launches on an Android 16 emulator.
ide
added a commit
to expo/react-native
that referenced
this pull request
Dec 5, 2026
Why === RN Tester's Android Release build failed with "Duplicate resources": its color gallery bundles `color/pq.avif` and `color/pq.heic`, and both became the raw resource `js_assets_color_pq`. Android ignores the extension when it assigns a resource ID, and raw resources of every format share one folder. Frontier named a raw resource with its format to avoid this, but upstream's version of the same change (react#60371) does not, and the rebase dropped frontier's copy as merged. How === `getAndroidResourceIdentifier` appends the format to the name of a raw resource (`color_pq_heic` beside `color_pq_avif`), and leaves drawable names unchanged. The bundler writes the resource under that name and `AssetSourceResolver` looks it up by the same name, since both call this function. Test Plan ========= `yarn jest packages/asset-utils packages/community-cli-plugin/src/commands/bundle packages/react-native/Libraries/Image` passes, including a test that two raw assets differing only in format get different identifiers. `./gradlew :packages:rn-tester:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds and packages `js_assets_color_pq_avif` and `js_assets_color_pq_heic`, and the app launches on an Android 16 emulator.
ide
added a commit
to expo/react-native
that referenced
this pull request
Dec 5, 2026
Why === RN Tester's Android Release build failed with "Duplicate resources": its color gallery bundles `color/pq.avif` and `color/pq.heic`, and both became the raw resource `js_assets_color_pq`. Android ignores the extension when it assigns a resource ID, and raw resources of every format share one folder. Frontier named a raw resource with its format to avoid this, but upstream's version of the same change (react#60371) does not, and the rebase dropped frontier's copy as merged. How === `getAndroidResourceIdentifier` appends the format to the name of a raw resource (`color_pq_heic` beside `color_pq_avif`), and leaves drawable names unchanged. The bundler writes the resource under that name and `AssetSourceResolver` looks it up by the same name, since both call this function. Test Plan ========= `yarn jest packages/asset-utils packages/community-cli-plugin/src/commands/bundle packages/react-native/Libraries/Image` passes, including a test that two raw assets differing only in format get different identifiers. `./gradlew :packages:rn-tester:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds and packages `js_assets_color_pq_avif` and `js_assets_color_pq_heic`, and the app launches on an Android 16 emulator.
ide
added a commit
to expo/react-native
that referenced
this pull request
Dec 5, 2026
Why === RN Tester's Android Release build failed with "Duplicate resources": its color gallery bundles `color/pq.avif` and `color/pq.heic`, and both became the raw resource `js_assets_color_pq`. Android ignores the extension when it assigns a resource ID, and raw resources of every format share one folder. Frontier named a raw resource with its format to avoid this, but upstream's version of the same change (react#60371) does not, and the rebase dropped frontier's copy as merged. How === `getAndroidResourceIdentifier` appends the format to the name of a raw resource (`color_pq_heic` beside `color_pq_avif`), and leaves drawable names unchanged. The bundler writes the resource under that name and `AssetSourceResolver` looks it up by the same name, since both call this function. Test Plan ========= `yarn jest packages/asset-utils packages/community-cli-plugin/src/commands/bundle packages/react-native/Libraries/Image` passes, including a test that two raw assets differing only in format get different identifiers. `./gradlew :packages:rn-tester:android:app:assembleRelease -Preact.internal.useHermesStable=true -PreactNativeArchitectures=arm64-v8a` succeeds and packages `js_assets_color_pq_avif` and `js_assets_color_pq_heic`, and the app launches on an Android 16 emulator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Fresco 3.9.0 reads a HEIF image's EXIF orientation with
androidx.exifinterface.media.ExifInterface(com.facebook.imageutils.HeifExifUtil.getOrientation, inimagepipeline-base), but no Fresco 3.9.0 artifact declares a dependency onandroidx.exifinterface, and neither does ReactAndroid. An app that does not get ExifInterface some other way throws when it decodes its first HEIC or HEIF image:HeifExifUtilcatches onlyIOException, and the error is thrown on a background thread, so it ends the process. A HEIC image bundled with the app also needs #60372, which letsImageload it fromres/raw.ReactAndroid now depends on
androidx.exifinterface:exifinterface1.4.2, declared in the version catalog, so every app that gets Fresco through React Native also gets the class. An app that declares an older ExifInterface resolves to 1.4.2.Changelog:
[ANDROID] [FIXED] - Include the ExifInterface dependency that Fresco needs to decode HEIC and HEIF images
Test Plan:
main(94aee19ac9): "No dependencies matching given input were found in configuration ':packages:react-native:ReactAndroid:debugRuntimeClasspath'".androidx.exifinterface:exifinterface:1.4.2is on that runtime classpath.None of the Fresco 3.9.0 POMs on Maven Central mentions
exifinterface, andjavap -p -conHeifExifUtilfromimagepipeline-base-3.9.0.aarshowsnew androidx/exifinterface/media/ExifInterfacewith an exception table that covers onlyjava/io/IOException.#60420 adds a Robolectric test that calls
HeifExifUtil.getOrientationand fails without this dependency.ktfmt is clean. Not run: decoding a HEIC image on a device or emulator.