Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native : Need Help Accessing Android Bundled Images with React-Native-Fetch-Blob

I have a folder of Images in my project

I'm struggling to access an image like this ProjectRoot/App/Images/image.png

in iOS I can access it by using:

RNFetchBlob.fs.dirs.MainBundleDir + 'assets/App/Images/image.png'

What would be the Android way? I've tried DocumentDir and MainBundleDir, I've only had a "file doesn't exist" returned

I have tried RNFetchBlob.fs.asset('image.png') and RNFetchBlob.fs.asset('path/to/image.png') and haven't been successful

I've logged out all the files and directories that I have access to and unfortunately I cannot find it

Need some help.

It is suggested that you can add

aaptOptions, noCompress to prevent assets in the Android assets folder from compressing into the bundle, however they exit outside of the Android project folder structure

"react-native": "0.49.1", "react-native-fetch-blob": "0.10.8",

Android: buildToolsVersion "23.0.1" targetSdkVersion 23

like image 739
Andrew Whale Avatar asked Feb 06 '18 08:02

Andrew Whale


1 Answers

I solved it in my instance.

Basically, and unfortunately, you need to duplicate the assets into your Android asset folder

e.g.

ProjectRoot/App/Images/image.jpg

must be copied to

ProjectRoot/android/app/src/main/assets/image.jpg

(subfolders can be used if needed)

rerun your packager and then the files are accessible by

RNFetchBlob.fs.asset("image.jpg")
like image 157
Andrew Whale Avatar answered Nov 14 '22 07:11

Andrew Whale