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

error: constructor ReactModuleRegistryProvider in class ReactModuleRegistryProvider cannot be applied to given types;

Open VitaliyGaliy opened this issue 4 years ago • 13 comments

error: constructor ReactModuleRegistryProvider in class ReactModuleRegistryProvider cannot be applied to given types; required: List<Package>,List<SingletonModule> found: List<Package> reason: actual and formal argument lists differ in length

Please HELP!

VitaliyGaliy avatar Mar 30 '20 14:03 VitaliyGaliy

Try removing the second argument from the constructor. The documentation hasn't been updated yet for the version you have installed (we will be releasing the new SDK shortly).

sjchmiela avatar Mar 30 '20 14:03 sjchmiela

I have this structure, please tell me what exactly is wrong, I am not a java dev unfortunately :(

package com.videocalls;

import com.videocalls.generated.BasePackageList;
import org.unimodules.adapters.react.ModuleRegistryAdapter;
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
import org.unimodules.core.interfaces.SingletonModule;
import java.util.Arrays;

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;

public class MainApplication extends Application implements ReactApplication {
private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(new BasePackageList().getPackageList());
  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 MyReactNativePackage());
          // packages.add(new WebRTCModulePackage());

      // Packages that cannot be autolinked yet can be added manually here, for example:
      // packages.add(new MyReactNativePackage());

      // Add unimodules
      List<ReactPackage> unimodules = Arrays.<ReactPackage>asList(
        new ModuleRegistryAdapter(mModuleRegistryProvider)
      );
      packages.addAll(unimodules);
          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.videocalls.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();
      }
    }
  }
}

VitaliyGaliy avatar Mar 30 '20 14:03 VitaliyGaliy

Oh, that's actually the other way around. Change:

-private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(new BasePackageList().getPackageList());
+private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(new BasePackageList().getPackageList(), null);

sjchmiela avatar Mar 30 '20 14:03 sjchmiela

sorry, my fault! Thanx a lot! it works!

VitaliyGaliy avatar Mar 30 '20 14:03 VitaliyGaliy

Great support!!! Amazing!

VitaliyGaliy avatar Mar 30 '20 14:03 VitaliyGaliy

Awesome.. got stuck with the same issue, and was lucky to find this recent issue. And fixed my build.

sonicvision avatar Mar 30 '20 15:03 sonicvision

Oh, that's actually the other way around. Change:

-private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(new BasePackageList().getPackageList());
+private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(new BasePackageList().getPackageList(), null);

@sjchmiela Looks like the linked diff for react-native >= 0.60 in readme is incorrect then. The second parameter is missing which leads to the error mentioned in this issue.

gramberg avatar Mar 31 '20 10:03 gramberg

Thank you for notifying us, @mczernek is already on it, updating the documentation! 🙏

sjchmiela avatar Mar 31 '20 10:03 sjchmiela

error: constructor ModuleRegistryAdapter in class ModuleRegistryAdapter cannot be applied to given types; new ModuleRegistryAdapter(), ^ required: ReactModuleRegistryProvider found: no arguments reason: actual and formal argument lists differ in length

Getting same error, I using react-native version "0.62.2", can any one help me please

gayathri-17 avatar Jul 05 '20 15:07 gayathri-17

I removed @unimodules/react-native-adapter from my package.json and I no longer got the issue. I guess that is because there was an incompatibility between the one used by react-native and the one in my package.json.

woodcockjosh avatar Dec 06 '20 17:12 woodcockjosh

If you remove @unimodules/react-native-adapter can you even build your app for release?

atalon-kn avatar May 25 '21 09:05 atalon-kn

Hi @sjchmiela , I strictly followed this documentation: https://docs.expo.io/bare/installing-unimodules/#configuration-for-android but still get the error.

I notice that there was a warning from Android Studio:

  • Duplicated content roots detected Path [/Users/atalon/Dev/lonlonmall/node_modules/@unimodules/react-native-adapter/android] of module [lonlonmall.unimodules-react-native-adapter] was removed from modules [lonlonmall.unimodules_react-native-adapter]

Not sure what went wrong, do you have any suggestions?

environment: expo CLI 4.4.7 environment info: System: OS: macOS 11.3 Shell: 5.8 - /bin/zsh Binaries: Node: 14.16.0 - /usr/local/bin/node npm: 6.14.11 - /usr/local/bin/npm Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 IDEs: Xcode: 12.5/12E262 - /usr/bin/xcodebuild npmPackages: @expo/webpack-config: ^0.12.64 => 0.12.64 expo: ^40.0.1 => 40.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: ~0.63.4 => 0.63.4 react-native-web: ^0.15.0 => 0.15.0 npmGlobalPackages: expo-cli: 4.4.7 Expo Workflow: bare

atalon-kn avatar May 25 '21 10:05 atalon-kn

upgraded my project to sdk 41 and the issue still occurs

Expo CLI 4.4.7 environment info: System: OS: macOS 11.3 Shell: 5.8 - /bin/zsh Binaries: Node: 14.16.0 - /usr/local/bin/node npm: 6.14.11 - /usr/local/bin/npm Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 IDEs: Xcode: 12.5/12E262 - /usr/bin/xcodebuild npmPackages: @expo/webpack-config: ~0.12.63 => 0.12.73 expo: ^41.0.0 => 41.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: ~0.63.4 => 0.63.4 react-native-web: ^0.16.3 => 0.16.3 npmGlobalPackages: expo-cli: 4.4.7 Expo Workflow: bare

atalon-kn avatar May 26 '21 09:05 atalon-kn