Saturday, January 26, 2019

Could not find method google() for arguments [] on repository container In React Native

Sometime during the mobile application development using react native library, you have seen this "Could not find method google() for arguments [] on repository container" error message in your console or terminal. This is a most common type comparability issues in react native application for that you need to either downgrade the library version or else you need to upgrade your Android project gradle version.


Lets see below real time example, where we have installed Realm library in react native application and we are using react native version 0.54 for application development. But during compilation we are getting below error message in console.

FAILURE: Build failed with an exception.

* Where:
Build file '~/myprj/node_modules/react-native-camera/android/build.gradle' line: 4

* What went wrong:
A problem occurred evaluating project ':realm'.
> Could not find method google() for arguments [] on repository container.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Solution we have modified below details in react native project folder :

Step-1:- Open gradle-wrapper.properties file and modify the distributionUrl section as per below
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

After modification file structure should look like this :
gradle/wrapper/gradle-wrapper.properties

Step-2:-  Add the below highlighted line in your build.gradle file and provide the updated gradle version in dependencies section.
Top level build.gradle is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        google()
    }
}

Follow the mentioned steps, this may fixed your problem in react native application.


1 comment:

  1. it works for me on android studio...same instruction was follow

    ReplyDelete