fix: iOS production builds fail to load bundled .riv assets#12
Merged
fix: iOS production builds fail to load bundled .riv assets#12
Conversation
2ecd9e7 to
c35dbd7
Compare
c35dbd7 to
80ef83d
Compare
Fixes production build issue where iOS bundled assets fail to load. **Problem:** On iOS, `resolveAssetSource()` returns file:// URLs for bundled assets: `file:///path/to/app/assets/rive/rewards_source.riv` The previous implementation tried to extract the filename and load it as a bundle resource, which only worked in debug builds. In production, assets are packaged as actual files in the app bundle, not as named resources accessible via `Bundle.main.path(forResource:)`. **Previous approach (broken in production):** ```typescript // Extract "rewards_source" from file URL const match = assetURI.match(/file:\/\/(.*\/)+(.*)\.riv/); return RiveFileFactory.fromResource(match[2], loadCdn); // ❌ Failed: "Could not find Rive file: rewards_source.riv" ``` **New approach (works in debug and production):** ```typescript // Load directly from file:// URL return RiveFileFactory.fromFileURL(assetURI, loadCdn); // ✅ Reads file directly from disk ``` **Implementation:** - Added `fromFileURL` to `RiveFile.nitro.ts` spec - Implemented `fromFileURL` in iOS (`HybridRiveFileFactory.swift`) - Validates file:// URL scheme - Loads data directly from file path using `Data(contentsOf:)` - Runs on background thread - Implemented `fromFileURL` in Android (`HybridRiveFileFactory.kt`) - Matches iOS validation behavior - Converts URI to path using `java.net.URI` - Loads on `Dispatchers.IO` background thread - Updated `fromSource()` to use `fromFileURL()` for file:// URLs - Regenerated Nitrogen boilerplate 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
80ef83d to
246eaed
Compare
HayesGordon
reviewed
Nov 3, 2025
HayesGordon
reviewed
Nov 3, 2025
HayesGordon
reviewed
Nov 3, 2025
HayesGordon
previously approved these changes
Nov 3, 2025
Contributor
HayesGordon
left a comment
There was a problem hiding this comment.
Looks great! Thanks for this.
Likely something we can/should revisit for the old runtime as well?
Co-authored-by: Gordon <pggordonhayes@gmail.com>
HayesGordon
approved these changes
Nov 3, 2025
Collaborator
Author
We don't have this issue in old runtime, but we don't support require there - which we should |
mfazekas
added a commit
that referenced
this pull request
Nov 17, 2025
* fix: iOS production asset loading Fixes production build issue where iOS bundled assets fail to load. **Problem:** On iOS, `resolveAssetSource()` returns file:// URLs for bundled assets: `file:///path/to/app/assets/rive/rewards_source.riv` The previous implementation tried to extract the filename and load it as a bundle resource, which only worked in debug builds. In production, assets are packaged as actual files in the app bundle, not as named resources accessible via `Bundle.main.path(forResource:)`. **Previous approach (broken in production):** ```typescript // Extract "rewards_source" from file URL const match = assetURI.match(/file:\/\/(.*\/)+(.*)\.riv/); return RiveFileFactory.fromResource(match[2], loadCdn); // ❌ Failed: "Could not find Rive file: rewards_source.riv" ``` **New approach (works in debug and production):** ```typescript // Load directly from file:// URL return RiveFileFactory.fromFileURL(assetURI, loadCdn); // ✅ Reads file directly from disk ``` **Implementation:** - Added `fromFileURL` to `RiveFile.nitro.ts` spec - Implemented `fromFileURL` in iOS (`HybridRiveFileFactory.swift`) - Validates file:// URL scheme - Loads data directly from file path using `Data(contentsOf:)` - Runs on background thread - Implemented `fromFileURL` in Android (`HybridRiveFileFactory.kt`) - Matches iOS validation behavior - Converts URI to path using `java.net.URI` - Loads on `Dispatchers.IO` background thread - Updated `fromSource()` to use `fromFileURL()` for file:// URLs - Regenerated Nitrogen boilerplate 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Update src/core/RiveFile.ts Co-authored-by: Gordon <pggordonhayes@gmail.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Gordon <pggordonhayes@gmail.com>
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.
Problem
iOS production builds fail to load bundled
.rivassets with error:Root Cause
On iOS,
resolveAssetSource()returns file:// URLs for bundled assets:The previous implementation:
rewards_sourcefromResource("rewards_source")Why it failed in production:
In production, assets exist as physical files in the app bundle deeper, not as named resources accessible via
Bundle.main.path(forResource:).Solution
Load bundled assets directly from their file:// URLs instead of trying to extract and load as bundle resources. To support this fix, added
fromFileURL()method toRiveFileFactory: