21

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
  • 221
  • 1
  • 2
  • 6

5 Answers5

48

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
  • 734
  • 6
  • 7
  • 1
    I had to read all stuff above, to come to something with +18 that will work. This happens when people do not accept answers. – H.A.H. Oct 14 '20 at 09:41
  • The true answer. Usually encounter this when I am going manage old projects – Yeung Apr 13 '21 at 06:01
  • This resolves the issue but in my case, it requires gradle-6.5-bin.zip – neo May 08 '21 at 11:16
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
0

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

0

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

maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
Pankaj Kant Patel
  • 1,820
  • 15
  • 26
-3

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
  • 16,545
  • 10
  • 76
  • 108