react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Native module Vibration tried to override com.facebook.react.modules.vibration.VibrationModule

Open Nonchalantcode opened this issue 4 years ago • 7 comments

Hi, I get the above error right after the application successfully compiles. The full error message is:

Native module Vibration tried to override com.facebook.react.modules.vibration.VibrationModule. Check the getPackages() method in MainApplication.java, it might be that module is being created twice. If this was your intention, set canOverrideExistingModule=true. This error may also be present if the package is present only once in getPackages() but is also programatically added later during build time by autolinking. Try removing the existing entry and rebuild.

For reference, my MainApplication.java file looks like this (no Vibration module is being added in the getPackages() method):

package com.zknotifications;
import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import com.rnfs.RNFSPackage;
import com.facebook.react.shell.MainReactPackage;
public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost =
      new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
          return BuildConfig.DEBUG;
        }

        @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 MainReactPackage());
          packages.add(new RNFSPackage());
          return packages;
        }

        @Override
        protected String getJSMainModuleName() {
          return "index";
        }
      };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
  }

  /**
   * Loads Flipper in React Native templates. Call this in the onCreate method with something like
   * initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
   *
   * @param context
   * @param reactInstanceManager
   */
  private static void initializeFlipper(
      Context context, ReactInstanceManager reactInstanceManager) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
        Class<?> aClass = Class.forName("com.zknotifications.ReactNativeFlipper");
        aClass
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
            .invoke(null, context, reactInstanceManager);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}

I'm using React Native 0.64.1 and react-native-fs 2.18.0 Any ideas of what the issue could be? This error only comes up after having gone through the set up of react-native-fs

Nonchalantcode avatar Jul 22 '21 04:07 Nonchalantcode

Did you solve it? I got the same issue with you

Manjioko avatar Sep 02 '21 03:09 Manjioko

I'm also trying to install react-native-fs. I found that the documentation on github has something I don't need for the latest version of React. React's auto linking already adds this package to MainApplication.java, so for the latest version, the last step is to be disregarded as I understand it.

FranciscoOssian avatar Sep 30 '21 13:09 FranciscoOssian

I also tried. The latest version doesn't need to do this step

steelegg avatar Mar 24 '22 05:03 steelegg

Anybody knows how to solve it?

YanaSyritskaya avatar May 25 '22 14:05 YanaSyritskaya

anybody fix this crap

AbdulmalekAlshugaa avatar Jun 25 '22 10:06 AbdulmalekAlshugaa

delete this line import com.facebook.react.shell.MainReactPackage; and this packages.add(new MainReactPackage());. it helped me

stasguma avatar Aug 02 '22 09:08 stasguma

Remove packages.add(new MainReactPackage()); from the getPackages() function of MainApplication.java

I notice this issue occurs if you have below setting as false BuildConfig.java public static final boolean IS_NEW_ARCHITECTURE_ENABLED = false;

If above flag is true then with above MainReactPackage() added to package list is working. This working in another project of mine.

somshine avatar Oct 15 '23 13:10 somshine