[Android] Fatal crash (FileNotFoundException) when loading .lottie from file:// URI (CodePush/OTA) on some devices

Open Beginner friendly
#1,415 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
android, kotlin, react-native
Domain
mobile

Research direction

Start in LottieAnimationViewPropertyManager.kt, especially commitChanges and the file:// handler around lines 150–157, and compare it with the guarded block above. Verify the missing-file path is handled without opening a stream or crashing, while an available .lottie file still loads normally.

Written by the indexing model from the issue text.

Description

Description

Description

The file:// URI handler in LottieAnimationViewPropertyManager.kt (introduced by PR #1319 to support CodePush/OTA updates) opens a FileInputStream without checking if the file exists first. This causes an uncaught java.io.FileNotFoundException that fatally crashes the app on the main thread.

This is inconsistent with the code block immediately above it (lines 136–144), which correctly performs a file.exists() guard before opening.

The buggy code at lines 150–157:

if (scheme == "file") {
    val uri = Uri.parse(assetName)
    uri.path?.let { path ->
        val fileWithScheme = File(path)
        // ❌ No file.exists() check — crashes if file is unavailable
        view.setAnimation(
            ZipInputStream(FileInputStream(fileWithScheme)),
            assetName.hashCode().toString()
        )
    }
}
Key observations
  • The crash does not happen for all users. The same CodePush bundle works for the majority of users. Only a subset of users (likely those with slower I/O, low storage, or specific OEMs) hit this crash.
  • CodePush hash verification confirms all files are present at install time, but the file can become transiently unavailable when the LottieView is pre-allocated during Fabric's frame callback on the next app restart.
  • Other React Native native components (e.g., Image via Fresco) handle FileNotFoundException gracefully. Only LottieView crashes fatally because of the missing guard.
Crash log
FATAL EXCEPTION: main
Process: money.digital.payments, PID: 20659
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:610)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1005)
Caused by: java.lang.reflect.InvocationTargetException
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:600)
Caused by: java.io.FileNotFoundException:
  /data/user/0/money.digital.payments/files/CodePush/.../CodePush/raw/src_assets_lottie_loader.lottie:
  open failed: ENOENT (No such file or directory)
  at libcore.io.IoBridge.open(IoBridge.java:574)
  at java.io.FileInputStream.<init>(FileInputStream.java:179)
  at com.airbnb.android.react.lottie.LottieAnimationViewPropertyManager.commitChanges(LottieAnimationViewPropertyManager.kt:155)
  at com.airbnb.android.react.lottie.LottieAnimationViewManagerImpl.setSourceDotLottieURI(LottieAnimationViewManagerImpl.kt:205)
  at com.airbnb.android.react.lottie.LottieAnimationViewManager.setSourceDotLottieURI(LottieAnimationViewManager.kt:143)
  at com.facebook.react.viewmanagers.LottieAnimationViewManagerDelegate.setProperty(LottieAnimationViewManagerDelegate.java:44)
  at com.facebook.react.uimanager.ViewManager.updateProperties(ViewManager.java:103)
  at com.facebook.react.uimanager.ViewManager.createViewInstance(ViewManager.java:230)
  at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:148)
  at com.facebook.react.fabric.mounting.SurfaceMountingManager.createViewUnsafe(SurfaceMountingManager.java:673)
  at com.facebook.react.fabric.mounting.SurfaceMountingManager.preallocateView(SurfaceMountingManager.java:1083)
  at com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem.execute(PreAllocateViewMountItem.kt:39)
  at com.facebook.react.fabric.FabricUIManager$DispatchUIFrameCallback.doFrameGuarded(FabricUIManager.java:1513)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
  at libcore.io.Linux.open(Native Method)
Suggested fix

Add a file.exists() check before the FileInputStream, consistent with the existing pattern at line 137:

if (scheme == "file") {
    val uri = Uri.parse(assetName)
    uri.path?.let { path ->
        val fileWithScheme = File(path)
        if (fileWithScheme.exists()) {
            view.setAnimation(
                ZipInputStream(FileInputStream(fileWithScheme)),
                assetName.hashCode().toString()
            )
        } else {
            Log.e(TAG, "Lottie file not found at path: $path (asset: $assetName). Skipping animation.")
        }
    } ?: Log.w(TAG, "URI path is null for asset: $assetName")
}
Related issues
  • #1098 — original issue about dotLottie not working after CodePush
  • #1319 — PR that introduced the file:// handler (which has this missing guard)
  • #1066 — crash when provided lottie link is broken
Environment
Key Value
lottie-react-native 7.3.4
react-native 0.82.0
Platform Android
Architecture Fabric (New Architecture)
Build type Release app & production bundle
Device Real device
OTA tool CodePush
Steps to reproduce
  1. Use lottie-react-native with .lottie files bundled via require() in a React Native app
  2. Push an OTA update via CodePush (or any OTA tool)
  3. Restart the app to apply the CodePush update
  4. Navigate to a screen that renders a using a .lottie asset
  5. On some devices (particularly lower-end or storage-constrained), the app crashes with FileNotFoundException
Snack or a link to a repository

N/A — This is a native-layer issue in LottieAnimationViewPropertyManager.kt that only manifests in OTA (CodePush/Expo Updates) scenarios on real devices, which cannot be reproduced in a Snack. The bug is visible by reading the source code at line 150-157 of LottieAnimationViewPropertyManager.kt where the file:// URI handler lacks a file.exists() check that is present in the block above (line 137).

Lottie React Native version

7.3.4

React Native version

0.82.0

Platforms

Android

Workflow

React Native

Architecture

Fabric (New Architecture)

Build type

Release app & production bundle

Device

Real device

Acknowledgements

Yes

Dominant language
TypeScript
Stars
17.2k
Forks
1.8k
Avg merge
6h 50m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from lottie-react-native/lottie-react-native

All issues in lottie-react-native/lottie-react-native

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.