2

I installed react-native-fs and I followed through the document. I did all the configuration but at the last, they mentioned I should make the changes in MainApplication.java . But configuration is not the same as their document.

react-native-fs ==> MainApplication.java

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
      );
    }

My app ===> MainApplication.java

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;
        }
AsZik
  • 621
  • 1
  • 4
  • 20

1 Answers1

2

react-native-fs installation instructions were written long time ago when autolinking was not there(prior to React Native v0.60.0 release).

Firstly, if you are using React Native version 0.60.0+, then you do not have to perform any additional android and iOS(except the pod install for iOS) steps as described in the Readme.md of the package since autolinking will automatically handle the native configuration part.

But if you still want to manually link the library, then in your given android code in MainApplication.java file, you can add the new RNFSPackage() as shown in the code snippet below.

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());
          packages.add(new RNFSPackage()); //<== here
          return packages;
        }
Ajay
  • 450
  • 3
  • 11