Manual link react-native-fs in react native

3k Views Asked by At

I'm mac user and "react-native link react-native-fs" doesn’t work for me. How to manually link this? its just matter for me to work in android.

and please check that im do the right thing till here first thing i do is

npm install react-native-fs --save

then i do this in android/setting.gradle

include ':react-native-fs'
project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react- 
native-fs/android')

and after that in android/app/build.gradle i add this

dependencies {
...
implementation project(':react-native-fs')
}

and in this step in tutorial said do this

import com.rnfs.RNFSPackage; // <------- add package

public class MainApplication extends Application implements ReactApplication {
// ...
@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
    new MainReactPackage(), // <---- add comma
    new RNFSPackage() // <---------- add package
  );
}

but my code is little bit diffrent and thats it

@Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      // packages.add(new MyReactNativePackage());
      //return packages;
      return packages(
    new MainReactPackage(), // <---- add comma
    new RNFSPackage() // <---------- add package
  );
    }

and at this step tutorial said to do 'react-native link react-native-fs' but it doesn't work for me so i think the solution is to link manually but i dont know how to do that

1

There are 1 best solutions below

1
On

Process to link should be like this

npm install react-native-fs --save

once installed you have to link the same dependency to the gradle file

npm link react-native-fs

open your settings.gradle file and the linking should be there. If not then only manually add

include ':react-native-fs'
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')

go to your build.gradle file of Module app and add the missing dependency

dependencies {
    implementation project(':react-native-fs')
    // your other implementations 

}