Currently, the expo-gl systems seems like that it only accepts file:// for texImage2d, and using downloadAsync worked fine while working in dev. But on release, the Asset is no more on the network, and doing downloadAsync wont give a file://
¿what can I do?
Some people suggest using react-native-fs - npm but I would like to avoid keep adding stuff to the project. I feel like there may be a way and I am missing it
Thanks’ for your time
I tried, and it still doesn’t work.
Oh I forgot to mention I am building for Android
But I think I misexplained myself, the Asset I’m trying to fetch comes fromModule(require(etc)), and it does not have a file:// prefix (and I wish it had, that’s the problem). That fragment of code seems to prevent downloading a file twice, or something
This is one of the Asset and how it looks like (in release)
The require is kinda like require('./skins/demonhead_splash/demonhead_base_negro.png')
In debug, it makes sense, since as far as I understood, it is served from the metro. So when I Asset.downloadAsync it gives a correct localUri. But when I do release, and it is bundled in the app, this happens, and doing downloadAsync does not give a localUri with file:// prefix, it just keeps this weird plain uri (that I don’t have been able to learn what is for, or why it looks like that)
This is related specifically with this Issue
In this Issue, the workaround is with the module I mentioned before, react-native-fs (file system) but I am trying to avoid it if possible
You are gonna love how I solved it… or hate it, not sure
I was looking around the libraries and digging and stuff, and I came across a bunch of stuff (some might be obvious to you, but to me where all discoveries, jaja)
First, I wondered where and how assets are bundled on the apk with React Native, and they go to the res folder, but, the subfolder they end up is dependant on their extension, so png,jpg,webp,… go to drawables ¿right?
Then I noticed the expo-asset download was basically expo-file-system download, and I followed that trail until I found this bunch of code in the expo-file-system library:
mmmhhh… interesting… if (!url.contains(":")) is for the bundled assets, is what I had noticed before, that their uri is just a name without prefix. And then resources.getIdentifier(url, "raw", packageName);!
raw… the thing tries to do the downloads, from the resources, but only in the raw folder. But since this assets are images, they are in the drawables folder…
So, since my specific problem was to get this images as textures for the GLContext, I really didn’t care if they weren’t drawables. So I converted their extension from .png to .xpng (because why not) and then added a bunch of code so React Native didn’t ignore those as trash
With that, the xpng are added to de bundle, in the raw subfolder (because react doesn’t know what they are for ¿I guess?)
Then when I get the asset with x = Asset.fromModule I also do x.type = 'png' (just in case, didn’t really tried leaving like 'xpng') and then doing x.downloadAsync works as expected, the resource is downloaded to the cache, and I can finally use it for gl.texImage2D
Well, thanks for reading
I propose that the expo-file-system should sweep all the resource types and not just the raw to avoid this in the future