简体   繁体   中英

Gradle error : Could not find com.android.tools.build:gradle:2.2.3

I'm trying to build my android project using gradle and circleCI, but I've got this error :

* What went wrong:
  A problem occurred configuring root project '<myproject>'.
  > 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:
     :<myproject>:unspecified

Can someone explain me why I've got this problem please?

It seems the current versions of the Android Gradle plugin are not added to Maven Central, but they are present on jcenter. Add jcenter() to your list of repositories and Gradle should find version 2.2.3 . On Maven Central the newest available version is 2.1.3 : http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.android.tools.build%22%20AND%20a%3A%22gradle%22 . You can also complain to the authors that the current versions are missing on Maven Central.

Reading sembozdemir answer in this post I have resolved a similar problem adding jcenter() in build.gradle (module: cordovaLib)

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }

}

After the recent update to Android Studio 3.0 Canary 1 , I got the following error:

> Could not resolve all dependencies for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.0.0-alpha1.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.jar
     Required by:
         project :

Here is what I had to add (to the project-level build.gradle):

buildscript {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
        ....            
    }

Found here: https://developer.android.com/studio/preview/features/new-android-plugin-migration.html

i had the same issue when i update my android studio to 3.0 then its solved by adding

buildscript {
     repositories {
    ...
    // You need to add the following repository to download the
    // new plugin.
    google()
}

dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
}
 }

from https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#update_gradle

在此处输入图片说明

buildscript {
repositories {
   mavenCentral()
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.3.0'
}

}

Just change the mavenCentral() to jcenter()

On my side I got the same issue because I used the wrong order of repositories.

google() should be added before jcenter()

buildscript {
    repositories {
        google()
        jcenter()
    }

Do you try it

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'

        // NOTE: Do not place your application dependencies here; they belong
    }

}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://jitpack.io"
        }
        flatDir {
            dirs 'libs'
        }

    }

}

and Build->Clear Project

Try this:

allprojects {
    buildscript {
        repositories {
            maven {
                url "https://dl.bintray.com/android/android-tools"
            }
        }
    }
...
}

Updating CordovaLib -> build.gradle also worked for me, as above. I was looking at the root build.gradle initially which was correct and already included jcenter().

Only go to the following path and delete the caches folder completely then rebuild the project:

C:\\Users\\[Your User Name]\\.gradle

将gradle版本更改为与android版本相同,如右图所示,我们正在使用gradle 2.3.2

Add jcenter in your project gradle file and sync

检查此为参考

The issue is caused by your type of internet connection which prevents or blocks Android Studio from downloading required files from jcenter, this should happen automatically when you build your solution. The solution to your problem is to connect to internet using your personal internet connection such as ADSL Router, rebuild the project and the download of necessary files will happen automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM