Skip to content

Ship ExifInterface so a HEIC image does not crash Android - #60371

Merged
cortinico merged 1 commit into
react:mainfrom
expo:@ide/android-heic-exifinterface
Nov 30, 2026
Merged

cortinico merged 1 commit into
react:mainfrom
expo:@ide/android-heic-exifinterface

Conversation

@ide

@ide ide commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fresco 3.9.0 reads a HEIF image's EXIF orientation with androidx.exifinterface.media.ExifInterface (com.facebook.imageutils.HeifExifUtil.getOrientation, in imagepipeline-base), but no Fresco 3.9.0 artifact declares a dependency on androidx.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:

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/exifinterface/media/ExifInterface;
        at com.facebook.imageutils.HeifExifUtil.getOrientation(HeifExifUtil.kt:31)
        at com.facebook.imagepipeline.image.EncodedImage.internalParseMetaData(EncodedImage.java:396)

HeifExifUtil catches only IOException, 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 lets Image load it from res/raw.

ReactAndroid now depends on androidx.exifinterface:exifinterface 1.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:

./gradlew :packages:react-native:ReactAndroid:dependencyInsight --dependency androidx.exifinterface --configuration debugRuntimeClasspath -Preact.internal.useHermesStable=true --console=plain
  • On main (94aee19ac9): "No dependencies matching given input were found in configuration ':packages:react-native:ReactAndroid:debugRuntimeClasspath'".
  • On this branch: androidx.exifinterface:exifinterface:1.4.2 is on that runtime classpath.

None of the Fresco 3.9.0 POMs on Maven Central mentions exifinterface, and javap -p -c on HeifExifUtil from imagepipeline-base-3.9.0.aar shows new androidx/exifinterface/media/ExifInterface with an exception table that covers only java/io/IOException.

#60420 adds a Robolectric test that calls HeifExifUtil.getOrientation and fails without this dependency.

ktfmt is clean. Not run: decoding a HEIC image on a device or emulator.

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>
@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
@ide
ide marked this pull request as ready for review November 29, 2026 12:02
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 29, 2026

@chrfalch chrfalch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.annotation resolves to 1.9.1 on both (requested by androidx.window:window-core-android:1.5.1). exifinterface asks for 1.8.1, so it doesn't move anything. The 1.6.0 in libs.versions.toml is already outvoted on main.
  • 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

Copy link
Copy Markdown
Contributor

Thanks for fixing this @ide

@cortinico
cortinico merged commit 00cecb8 into react:main Nov 30, 2026
111 checks passed
@ide

ide commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@chrfalch The test is in #60420. It calls Fresco's HeifExifUtil.getOrientation on a stream with an EXIF orientation tag and expects the orientation back. With the dependency removed, it fails with the same NoClassDefFoundError at HeifExifUtil.kt:31.

@ide
ide deleted the @ide/android-heic-exifinterface branch December 1, 2026 05:30
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.
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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants