rn-fetch-blob
rn-fetch-blob copied to clipboard
App crash on Android with Error: canceled due to java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()
I recently upgraded my app's react native library from 0.63 to 0.67.4 and I am now targeting,compiling for Android 12 (SDK 31) from Android 11 (SDK 30). I am using rn-fetch-blob v0.12.0 to fetch a PDF. After the upgrade I am now getting this error when trying to fetch:
canceled due to java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()
Is there additional setup/config changes to support SDK 31 (Android 12)? This https://github.com/joltup/rn-fetch-blob/issues/478 seems to report the same issue but it is for Android 9. My app was working when it was compiled for and targeting android 11.
Any help or suggestions will be highly appreciated.
- Library versions and config versions rn-fetch-blob 0.12.0 react-native 0.67.4
- Android config:
-
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
-
build.gradle
buildscript {
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
...
}
ext.kotlinVersion = '1.6.21'
repositories {
google()
mavenCentral()
...
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
...
}
}
- Sample code
import RNFetchBlob from "rn-fetch-blob";
import { Platform, PermissionsAndroid } from "react-native";
...
let allPermissionsGranted = false;
if (Platform.OS === "android") {
const granted = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
]);
allPermissionsGranted =
granted["android.permission.READ_EXTERNAL_STORAGE"] === "granted" && granted["android.permission.WRITE_EXTERNAL_STORAGE"] === "granted";
}
try {
const res = await RNFetchBlob.config({
trusty: true,
fileCache: false,
path: directory + "/" + filename,
}).fetch("GET", docUrl, headers);
const status = res.info().status;
if (status === 200) {
if (Platform.OS === "ios") {
RNFetchBlob.ios.openDocument(res.path());
} else {
if (allPermissionsGranted) {
const android = RNFetchBlob.android;
android.actionViewIntent(res.path(), mimetype);
}
}
}
} else {
console.log("Error fetching file");
throw new Error("...")
}
} catch (e) {
console.error(e);
}
Note: The try catch above is not catching the exception. The app crashes and closes when it gets the error.
The reported issue don't seem to occur when I updated to rn-fetch-blob 0.13.0-beta.1. Will a final version of this be releasing soon?
Nope it won't. Just switch to https://www.npmjs.com/package/react-native-blob-util
Same +1
+1
This repo is dead...
Any update on this? Facing this issue.
@christopher-18 yep, migrate to https://www.npmjs.com/package/react-native-blob-util
Solution https://stackoverflow.com/a/77329785/11762907 android/media/ Folder name should be the package name
The reported issue don't seem to occur when I updated to rn-fetch-blob 0.13.0-beta.1. Will a final version of this be releasing soon?
The issue reproduces for me on 0.13.0-beta.1 still :'(
wrapping the config with addAndroidDownloads solved this for me:
const configfb = {
addAndroidDownloads: {
useDownloadManager: true,
notification: true,
mediaScannable: true,
title: fileName,
path: `${dirToSave}/${fileName}`,
},
};