[file-system][android] add ability to read from bundle resources #8104
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.
Why
Once #8003 and #8006 land, some
require
bundled assets in bare workflow Android apps will be used directly from where they are embedded in the APK resources folder. (This is currently also the case for any bare workflow apps using expo-file-system without expo-updates.) These assets are inaccessible via the FileSystem API.For such assets, the
uri
returned by RN'sImage.resolveAssetSource
is actually just the resource name with no scheme. Therefore, in the FS API, if we receive a uri without a scheme we can assume it might be a file in resources and try to access it accordingly. We first try searching theres/raw
folder, and if the resource isn't found we try to find it inres/drawable
.How
Implemented the above plan for the three
FileSystem
methods that read data,getInfoAsync
,readAsStringAsync
, andcopyAsync
.Test Plan
tested in an Android bare app with a
require
d asset embedded in resourcesFileSystem.getInfoAsync(Image.resolveAssetSource(require('./asset.png')).uri)
resolves with expected infoFileSystem.readAsStringAsync(Image.resolveAssetSource(require('./asset.png')).uri)
resolves with expected infoFileSystem.copyAsync({from: Image.resolveAssetSource(require('./asset.png')).uri, to:
${FileSystem.documentDirectory}test.png)
resolves successfullyFileSystem.getInfoAsync('nonexistent-file')
resolves withexists: false
FileSystem.readAsStringAsync(nonexistent-file)
rejects with a readable error messageFileSystem.copyAsync({from: 'nonexistent-file, to:
${FileSystem.documentDirectory}test.png)
rejects with a readable error message