1

I am following Native Module documentation for android: https://facebook.github.io/react-native/docs/native-modules-android.html#docsNav

My package currently looks like this

package com.myCompany.asqgooglesignin;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ASQGoogleSignInPackage implements ReactPackage {

    @Override
    public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
        return Collections.emptyList();
    }

    @Override
    public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
        List<NativeModule> modules = new ArrayList<>();
        modules.add(new ASQGoogleSignIn(reactContext));
        return modules;
    }
}

and I am getting following error

class must either be declared abstract or implement abstract method called createJSModules in ReactPackage

Documentation does not mention anything about createJSModules should I include it and what is correct way to do so?

This is using latest dependency

implementation 'com.facebook.react:react-native:+'
Ilja
  • 44,142
  • 92
  • 275
  • 498

3 Answers3

3

yarn install helped in my case, because gradle was looking for react-native library aar file, and as it wasn't present, was falling back to an old version (0.20.1 - you can see it in the attached image)

attached image

AlVelig
  • 1,989
  • 15
  • 9
  • This is definitely the issue. Running `yarn install` or `npm install` didn't help for me, but Gradle loves to download and use ancient versions of React Native for some reason. – Andrew Koster Feb 01 '20 at 01:43
1

I think this method was removed in React Native version 0.47. Are you sure your React Native version is update to date in npm? You can can check your version by running react-native -v from your project directory. Any version above this shouldn't require that method to be implemented. If you don't want to change your version, try simply implementing the method with return Collections.emptyList();.

  • 1
    I had to include it in my project (this is a module) and it didn't use `maven( '.../node-modules/react-native/android" )` bit – Ilja Apr 20 '18 at 15:27
1

The Issue

Gradle cannot find the latest version of react-native in the repositories that you've provided.

The Reason

Due to the + used for the version:

implementation 'com.facebook.react:react-native:+'

gradle will search its known repositories for the latest react-native version available. Perhaps intentionally, the latest version published to the default maven repository was 0.20.1 in 2016. That version has a createJSModules method in the ReactPackage interface but this was removed in version 0.47.

This is probably why the + is used--by keeping maven central many years out of date, it indirectly ensures that developers are letting NPM manage their react-native version, rather than relying on Maven Central.

The Fix

Simply update your list of repositories to include your node_modules directory:

in build.gradle

repositories {
    mavenLocal()
    // This was missing an needs to be added to your list
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url("$rootDir/../node_modules/react-native/android")
    }
    google()
    jcenter()
    maven { url 'https://www.jitpack.io' }
}

Troubleshooting

If it still fails, confirm that this directory exists:

<path-to-your-project>/node_modules/react-native/android/com/facebook/react/react-native

If not, then make sure react-native is listed in your project.json file and then run rm -rf node_modules && yarn install

gMale
  • 17,147
  • 17
  • 91
  • 116