'On running my Code on Android Device I get an error as: Execution failed for task ':rn-fetch-blob:compileDebugJavaWithJavac'

I am using the rn-fetch-blob package to download files from url. But on running the code, on android it throws an error as: Execution failed for task ':rn-fetch-blob:compileDebugJavaWithJavac'.

In terminal: Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.

This is my code:

import React, { Component } from "react";
import {
  View,
  Text,
  Button,
  Alert,
  ProgressBarAndroid,
  ToastAndroid,
  PermissionsAndroid
} from "react-native";
import RNFetchBlob from "rn-fetch-blob";

export default class componentName extends Component {
  constructor(props) {
    super(props);
    this.state = {
      progress: 0,
      loading: false
    };
  }

  actualDownload = () => {
    this.setState({
      progress: 0,
      loading: true
    });
    let dirs = RNFetchBlob.fs.dirs;
    RNFetchBlob.config({
      // add this option that makes response data to be stored as a file,
      // this is much more performant.
      path: dirs.DownloadDir + "/path-to-file.png",
      fileCache: true
    })
      .fetch(
        "GET",
        "http://www.usa-essays.com/blog/wp-content/uploads/2017/09/sample-5-1024x768.jpg",
        {
          //some headers ..
        }
      )
      .progress((received, total) => {
        console.log("progress", received / total);
        this.setState({ progress: received / total });
      })
      .then(res => {
        this.setState({
          progress: 100,
          loading: false
        });
        ToastAndroid.showWithGravity(
          "Your file has been downloaded to downloads folder!",
          ToastAndroid.SHORT,
          ToastAndroid.BOTTOM
        );
      });
  };

  async downloadFile() {
    try {
      const granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
        {
          title: "Storage Permission",
          message: "App needs access to memory to download the file "
        }
      );
      if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        this.actualDownload();
      } else {
        Alert.alert(
          "Permission Denied!",
          "You need to give storage permission to download the file"
        );
      }
    } catch (err) {
      console.warn(err);
    }
  }
  render() {
    return (
      <View>
        <Text> Download Files in Android </Text>
        <Button onPress={() => this.downloadFile()} title="Download" />
        {this.state.loading ? (
          <ProgressBarAndroid
            styleAttr="Large"
            indeterminate={false}
            progress={this.state.progress}
          />
        ) : null}
      </View>
    );
  }
}


Solution 1:[1]

React native 0.60 brings some breaking changes both to Android and iOS.

For the android part the solution (workaround) is explained here: https://facebook.github.io/react-native/blog/2019/07/03/version-60#androidx-support

1) npm install --save-dev jetifier
2) npx jetify
3) npx react-native run-android
4) npx jetify

You will have to do step 4 everytime you add a new module or reset your node_modules folder.

Let me know if this solved your issue

Solution 2:[2]

For the RN 0.60.0, they are giving support for the AndroidX, You can use the following command to fix this issue.

npm i jetifier
npx jetify

You can refer the following doc for the AndroidX Support.

Ref: https://facebook.github.io/react-native/blog/2019/07/03/version-60

Solution 3:[3]

Please go to react-native-fetch-blob/android/build.gradle and update these values compileSdkVersion 23?buildToolsVersion "23.0.3"?defaultConfig {?minSdkVersion 16?targetSdkVersion 23?versionCode 1?versionName "1.0"?} to these compileSdkVersion 26?buildToolsVersion "26.0.3"?defaultConfig {?minSdkVersion 16?targetSdkVersion 26?versionCode 1?versionName "1.0"?}

Solution 4:[4]

I am not seeing any space before the exclamation (!) mark in the link when tried.

enter image description here

Try to open the JSON code of web activity in the pipeline and check if you see any spaces and remove them.

You can also use replace function to replace the space from the link with empty.

@replace('https://graph.microsoft.com/v1.0/sites/45078642-72ff-4519-bcce-21440e17a9bc/drives/b!QoYHRf9yGUW8ziFEDhepvOZxCMwcjRpKued1n_tDwksC4SLkzZJUTb_ymC6FSdiQ/root/children', ' ','')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Auticcat
Solution 2 Harsh Panchal
Solution 3 Muhammad Shahzaib
Solution 4 NiharikaMoola-MT