Skip to content

Fix loading of file:// URLs in Android release#329

Closed
ckknight wants to merge 1 commit intorive-app:mainfrom
ckknight:patch-1
Closed

Fix loading of file:// URLs in Android release#329
ckknight wants to merge 1 commit intorive-app:mainfrom
ckknight:patch-1

Conversation

@ckknight
Copy link
Copy Markdown
Contributor

This updates the definition of RiveReactNativeView.downloadUrlAsset to load file:// URLs via java.io.File

Formerly, if a file:// URL was loaded, that would lead to com.android.volley.VolleyError: java.lang.ClassCastException: sun.net.www.protocol.file.FileURLConnection cannot be cast to java.net.HttpURLConnection

This only affects Android apps built in release mode, as debug mode is unaffected.

This updates the definition of `RiveReactNativeView.downloadUrlAsset` to load `file://` URLs via `java.io.File`

Formerly, if a `file://` URL was loaded, that would lead to `com.android.volley.VolleyError: java.lang.ClassCastException: sun.net.www.protocol.file.FileURLConnection cannot be cast to java.net.HttpURLConnection`

This only affects Android apps built in release mode, as debug mode is unaffected.
@CacaoRick
Copy link
Copy Markdown

Before this change, I receive error when run an eas update bundle:

{
  "type": "IncorrectRiveFileUrl",
  "message": "Unable to download the Rive asset file form file:///data/user/0/com.rick.liao.riveapp/files/.expo-internal/49af8dbfa5974adf091e4d50f51edfdb.riv"
}

I can confirm that using this commit allows the local Rive file to be correctly loaded in EAS Update.

@joaqo
Copy link
Copy Markdown

joaqo commented Sep 11, 2025

Can't for the life of me make this work, is it supposed to just be something like this?

On my component

      <Rive
        url="file://assets/rive/logo.riv"
        style={{ width: 400, height: 400 }}
      />

On app.json under plugins

      [
        "expo-asset",
        {
          "assets": ["./assets/rive/logo.riv"]
        }
      ]

I have checked that the asset is loaded correctly by expo assets, and the rive component works perfectly with https:// urls, so no idea what the issue is.

@Hanro50
Copy link
Copy Markdown

Hanro50 commented Oct 10, 2025

I used this as a patch on Rive React Native version 9.6.1
It works well and allows Rive files to be used with Expo update on Android.

mfazekas added a commit to mfazekas/rive-react-native that referenced this pull request Nov 5, 2025
Simplify PR rive-app#329 implementation by removing unnecessary factory pattern
and using iOS-style approach with simple conditional dispatch.

Changes:
- Remove ResourceLoaderFactory, ResourceLoader interface, and implementations
- Replace factory pattern with simple if/else using URI.scheme
- Add loadFileUrlAsset() with background threading (Dispatchers.IO)
- Add loadRemoteUrlAsset() wrapping existing Volley logic
- Use proper URI parsing instead of string.startsWith()

Benefits:
- 50 fewer lines of code (net: -14 lines)
- Matches iOS architectural pattern (simple conditional dispatch)
- More maintainable - no unnecessary abstractions
- Uses URI.scheme for robust URL checking vs string matching
- Keeps critical improvements: background threading and error handling

Threading improvements:
- File I/O on Dispatchers.IO background thread
- Callbacks on main thread with withContext(Dispatchers.Main)
- Matches iOS pattern (DispatchQueue.global + DispatchQueue.main.async)

Error handling improvements:
- Check file existence and permissions before reading
- Return 404 NetworkResponse for FileNotFoundException
- Clear error messages for different failure modes

URL parsing improvements:
- Use java.net.URI instead of string.substring()
- Handles edge cases: file://, file:///, URL encoding
- Validates URI syntax properly
- Case-insensitive scheme checking

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
mfazekas added a commit to mfazekas/rive-react-native that referenced this pull request Nov 5, 2025
Simplify PR rive-app#329 implementation by removing unnecessary factory pattern
and using iOS-style approach with simple conditional dispatch.

Changes:
- Remove ResourceLoaderFactory, ResourceLoader interface, and implementations
- Replace factory pattern with simple if/else using URI.scheme
- Add loadFileUrlAsset() with background threading (Dispatchers.IO)
- Add loadRemoteUrlAsset() wrapping existing Volley logic
- Use proper URI parsing instead of string.startsWith()

Benefits:
- 50 fewer lines of code (net: -14 lines)
- Matches iOS architectural pattern (simple conditional dispatch)
- More maintainable - no unnecessary abstractions
- Uses URI.scheme for robust URL checking vs string matching
- Keeps critical improvements: background threading and error handling

Threading improvements:
- File I/O on Dispatchers.IO background thread
- Callbacks on main thread with withContext(Dispatchers.Main)
- Matches iOS pattern (DispatchQueue.global + DispatchQueue.main.async)

Error handling improvements:
- Check file existence and permissions before reading
- Return 404 NetworkResponse for FileNotFoundException
- Clear error messages for different failure modes

URL parsing improvements:
- Use java.net.URI instead of string.substring()
- Handles edge cases: file://, file:///, URL encoding
- Validates URI syntax properly
- Case-insensitive scheme checking

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
mfazekas added a commit to mfazekas/rive-react-native that referenced this pull request Nov 5, 2025
Simplify PR rive-app#329 implementation by removing unnecessary factory pattern
and using iOS-style approach with simple conditional dispatch.

Changes:
- Remove ResourceLoaderFactory, ResourceLoader interface, and implementations
- Replace factory pattern with simple if/else using URI.scheme
- Add loadFileUrlAsset() with background threading (Dispatchers.IO)
- Add loadRemoteUrlAsset() wrapping existing Volley logic
- Use proper URI parsing instead of string.startsWith()

Benefits:
- 50 fewer lines of code (net: -14 lines)
- Matches iOS architectural pattern (simple conditional dispatch)
- More maintainable - no unnecessary abstractions
- Uses URI.scheme for robust URL checking vs string matching
- Keeps critical improvements: background threading and error handling

Threading improvements:
- File I/O on Dispatchers.IO background thread
- Callbacks on main thread with withContext(Dispatchers.Main)
- Matches iOS pattern (DispatchQueue.global + DispatchQueue.main.async)

Error handling improvements:
- Check file existence and permissions before reading
- Return 404 NetworkResponse for FileNotFoundException
- Clear error messages for different failure modes

URL parsing improvements:
- Use java.net.URI instead of string.substring()
- Handles edge cases: file://, file:///, URL encoding
- Validates URI syntax properly
- Case-insensitive scheme checking

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
mfazekas added a commit to mfazekas/rive-react-native that referenced this pull request Nov 6, 2025
Simplify PR rive-app#329 implementation by removing unnecessary factory pattern
and using iOS-style approach with simple conditional dispatch.

Changes:
- Remove ResourceLoaderFactory, ResourceLoader interface, and implementations
- Replace factory pattern with simple if/else using URI.scheme
- Add loadFileUrlAsset() with background threading (Dispatchers.IO)
- Add loadRemoteUrlAsset() wrapping existing Volley logic
- Use proper URI parsing instead of string.startsWith()

Benefits:
- 50 fewer lines of code (net: -14 lines)
- Matches iOS architectural pattern (simple conditional dispatch)
- More maintainable - no unnecessary abstractions
- Uses URI.scheme for robust URL checking vs string matching
- Keeps critical improvements: background threading and error handling

Threading improvements:
- File I/O on Dispatchers.IO background thread
- Callbacks on main thread with withContext(Dispatchers.Main)
- Matches iOS pattern (DispatchQueue.global + DispatchQueue.main.async)

Error handling improvements:
- Check file existence and permissions before reading
- Return 404 NetworkResponse for FileNotFoundException
- Clear error messages for different failure modes

URL parsing improvements:
- Use java.net.URI instead of string.substring()
- Handles edge cases: file://, file:///, URL encoding
- Validates URI syntax properly
- Case-insensitive scheme checking

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@mfazekas mfazekas closed this in #389 Nov 6, 2025
mfazekas added a commit that referenced this pull request Nov 6, 2025
Simplify PR #329 implementation by removing unnecessary factory pattern
and using iOS-style approach with simple conditional dispatch.

Changes:
- Remove ResourceLoaderFactory, ResourceLoader interface, and implementations
- Replace factory pattern with simple if/else using URI.scheme
- Add loadFileUrlAsset() with background threading (Dispatchers.IO)
- Add loadRemoteUrlAsset() wrapping existing Volley logic
- Use proper URI parsing instead of string.startsWith()

Benefits:
- 50 fewer lines of code (net: -14 lines)
- Matches iOS architectural pattern (simple conditional dispatch)
- More maintainable - no unnecessary abstractions
- Uses URI.scheme for robust URL checking vs string matching
- Keeps critical improvements: background threading and error handling

Threading improvements:
- File I/O on Dispatchers.IO background thread
- Callbacks on main thread with withContext(Dispatchers.Main)
- Matches iOS pattern (DispatchQueue.global + DispatchQueue.main.async)

Error handling improvements:
- Check file existence and permissions before reading
- Return 404 NetworkResponse for FileNotFoundException
- Clear error messages for different failure modes

URL parsing improvements:
- Use java.net.URI instead of string.substring()
- Handles edge cases: file://, file:///, URL encoding
- Validates URI syntax properly
- Case-insensitive scheme checking

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

4 participants