[Android] Cannot write new files to storage in AVD emulator #231
Description
Hi there,
Thanks for maintaining this package with great API docs and examples. It's amazingly helpful.
While trying to implement file download functionality I encountered some frustrating behaviour I cannot explain while running a virtual android device: I can't write new files. Worse, react-native-fetch-blob
thinks it can write the file, reports no error, and responds with the expected path. But the file isn't written there. Overwriting an existing file works fine, so this isn't strictly a write permission issue. This problem does not happen when running on a real device.
Action:
Try to download a file to the local DocumentDirectory
on a virtual/emulated Android device as follows
const id = 123
const fileUrl = `http://some.example.com/stuff/${id}.mp3`
const fileDest = `${RNFetchBlob.fs.dirs.DocumentDir}/files/${id}.mp3`
yield RNFetchBlob
.config({
path: fileDest
})
.fetch('GET', fileUrl)
.then((resp) => {
console.log('RNFetchBlob result', resp.path())
})
.catch((rnfbErr) => {
console.log('RNFetchBlob error', rnfbErr)
})
which yields the expected output of: RNFetchBlob result /data/user/0/com.myappname/files/123.mp3
and no errors.
Expected result:
- See no errors
- See path logged out on success
- Find file at path
Actual Result:
- See no errors
- See path logged out on success
- Find no file at path 😢
Other Considerations:
- I do have
WRITE_EXTERNAL_STORAGE
permission inAndroidManifest.xml
and on startup I verify the permission explicitly viaPermissionsAndroid.checkPermission(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
which returnstrue
as expected. - This is reinforced by the fact that I am able to overwrite existing files. If I supply a
path
that already exists, the downloaded file will replace the pre-existing file. - This only happens on the AVD emulator. New files are created as expected on an actual device.
- I have tried different configurations of SD card storage in the AVD, such as "managed by studio" and supplying an image manually:
mksdcard -l e 128M sdcard.img
emulator -avd Nexus_5X_API_23 -sdcard sdcard.img
Target SDK: 23
Android Device & Version: Nexus 5X @ 6.0
RN: 0.34.1
RNFB: 0.10.2-beta.3