How to fix "ERROR: Could not find method google() for arguments [] on repository container." in android studio 3.5
Asked Answered
E

5

32

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

Egor answered 2/9, 2019 at 10:56 Comment(0)
W
61

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
Waldner answered 27/9, 2019 at 18:20 Comment(5)
I had to read all stuff above, to come to something with +18 that will work. This happens when people do not accept answers.Etch
The true answer. Usually encounter this when I am going manage old projectsCornaceous
This resolves the issue but in my case, it requires gradle-6.5-bin.zipMajewski
You can find the exact gradle version by going to build.gradle -> under dependencies classpath 'com.android.tools.build:gradle:<grade-leversion>'Edlun
work for me. should be marked as answerMajewski
C
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'
         }
    }
}
Contusion answered 14/6, 2020 at 3:26 Comment(1)
Thank you. I already fixed this problem a long time agoEgor
C
5

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

maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
Contorted answered 4/3, 2021 at 7:50 Comment(0)
M
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

Monophagous answered 8/12, 2019 at 3:33 Comment(0)
T
-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()
    }
}
Trembles answered 28/4, 2020 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.