Android Studio: Gradle Refresh Failed - Could not find com.android.tools.build:gradle:2.2.0-alpha6

前端 未结 7 1591
攒了一身酷
攒了一身酷 2020-12-24 01:46

I\'ve just pulled down an Android project from git, and Android Studio is giving me the following error whenever I attempt to open it;

Error:Could not find c         


        
相关标签:
7条回答
  • 2020-12-24 02:13

    This is because the build process is unable to find the dependency in Maven repository. Add jcenter() along with mavenCentral() in your project level build.gradle file.

    buildscript {
        repositories {
            mavenCentral()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.2.0'
        }
    }
    
    0 讨论(0)
  • 2020-12-24 02:15

    Replace the gradle:2.2.0-alpha6 to gradle:2.2.0-alpha3.
    If this doesn't work replace it to gradle:2.2.0-alpha2.

    0 讨论(0)
  • So I had a similar error while I was trying to build ionic2 project for android. This happened after android studio updated gradle during its updates.

    Error: cmd: Command failed with exit code 1 Error output:
    

    FAILURE: Build failed with an exception.

    • What went wrong: A problem occurred configuring root project 'android'.

      Could not resolve all dependencies for configuration ':_debugApk'. A problem occurred configuring project ':CordovaLib'. Could not resolve all dependencies for configuration ':CordovaLib:classpath'. Could not find com.android.tools.build:gradle:2.2.3. Searched in the following locations: https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar Required by: android:CordovaLib:unspecified

    I read the above answers which pointed to update a 'build.gradle' file but turns out there were multiple files with that name in the project. What worked for me (and hopefully helpful to whoever is working on angular2/ionic2 project and having this issue) is updating the build.gradle file at

    [rootOfPorject]/platforms/android/CordovaLib/build.gradle
    

    This file was missing the jcenter() entry and now the repository part looks like this and works like a charm.

    repositories {
        jcenter()
        mavenCentral()
    }
    

    Hope this saves time for someone else.

    EDIT: As @rcerecedar mentioned, you might also need to add jcenter() in the following file as well.

    [rootOfPorject]/platforms/android/build.gradle
    

    In this file you should check its present in buildscript -> repositories and also optionally in allprojects -> repositories

    0 讨论(0)
  • 2020-12-24 02:23

    If you have firewall configured in your PC,try the following in gradle.properties.

    systemProp.https.proxyHost=<proxyHostName>
    systemProp.https.proxyPort=8080
    systemProp.https.proxyUser=<user id>
    systemProp.https.proxyPassword=<password>
    systemProp.https.nonProxyHosts=www.google.com|localhost
    
    0 讨论(0)
  • 2020-12-24 02:25

    As gradle is updating the previous version will be replaced with new version so we have to change the gradle version in code as it would be referring to previous version and will show error like this

    Could not resolve all dependencies for configuration ':classpath'. Could not find com.android.tools.build:gradle:2.2.3. Searched in the following locations: file:/home/ubuntu/.m2/repository/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom file:/home/ubuntu/.m2/repository/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar https://oss.sonatype.org/content/repositories/snapshots/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom https://oss.sonatype.org/content/repositories/snapshots/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar Required by: :: Open file

    The solution to this is that we add the repository in the build.gradle file like

    buildscript {
    repositories {
        mavenCentral()
        google()
        jcenter()
    }
    

    OR

    GOTO the File Explorer and search

    C:\Program Files\Android\Android Studio\gradle\m2repository\com\android\tools\build\gradle
    

    and see the Gradle name with latest version like

    Gradle 2.2.0
    Gradle 3.2.1
    Gradle 2.1.0
    

    and select the latest version like 3.2.1 and paste it in the build.gradle file in dependencies section like

    dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'}
    
    0 讨论(0)
  • 2020-12-24 02:27

    1.Goto "C:\Program Files\Android\Android Studio\gradle\m2repository\com\android\tools\build\gradle"

    2.See the Latest folder name , i.e "2.2.3" , Copy It.

    3.Go to build.gradle(Module:yourapp) file ,

    Place here:

    buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }
    
    0 讨论(0)
提交回复
热议问题