31

I am trying to build and android project from an imported android source code; but each time I try building, I get this >> "ERROR: Could not find method google() for arguments [] on repository container". How do I fix it

I recently converted my Web Application to a Native android app via goNative.io; of which it built an apk I can install on my phone and the android source code. on building the project in my android studio, I get the error >> "ERROR: Could not find method google() for arguments [] on repository container". The bug was traced to my build.gradle. Here is what it looks like

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        //classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

I expected a "Build Successful" message so that I can upgrade my API Level to 28 the rebuild back to apk so that I can finally publish on google play store. Please help fellas

DUG
  • 319
  • 1
  • 3
  • 7

5 Answers5

60

set gradle-wrapper.properties file to:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

or higher

distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Mohammed Hamed
  • 859
  • 7
  • 7
10

enter image description here only add this line of code in build.gradle(module:app) file.

allprojects {
    repositories {
        jcenter()
         maven {
            url 'https://maven.google.com'
         }
    }
}
user10116728
  • 101
  • 1
  • 3
5

This solution working for me to replace google() tag with.

maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
Pankaj Kant Patel
  • 2,050
  • 21
  • 27
1

This error is sometimes generated when you try to run a project created using an older version of Flutter than the one you're currently using.

Causes When a project is created with flutter create foo several files in the ios/ and android/ sub-directories are created.

Newer Flutter versions might generate these files a bit differently and projects created with older Flutter versions might cause issues.

to fix:

Supposing that your project is in c:\root_of_your_project\name_of_your_project

Delete the ios/ and android/ directories and go to root directory of your project with CMD, and:

c:\root_of_your_project\flutter create -a kotlin name_of_your_project

and

c:\root_of_your_project\flutter create -i swift name_of_your_project

-4

You get this error if a google() dependency is not wrapped in a repositories block, so if you do something like this:

allprojects {
    google()
    mavenCentral()
    jcenter()
}

Should be:

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
}
Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135