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

本秂侑毒 提交于 2021-01-21 06:28:15

问题


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


回答1:


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



回答2:


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'
         }
    }
}



回答3:


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()
    }
}


来源:https://stackoverflow.com/questions/57755725/how-to-fix-error-could-not-find-method-google-for-arguments-on-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!