176

I updated the gradle plugin to the latest version : com.android.tools.build:gradle:3.0.0-alpha1 and this error occured in AS:

export TERM="dumb"
if [ -e ./gradlew ]; then ./gradlew test;else gradle test;fi

FAILURE: Build failed with an exception.

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

Current CI config circle.yml

dependencies:
   pre:
      - mkdir -p $ANDROID_HOME"/licenses"
      - echo $ANDROID_SDK_LICENSE > $ANDROID_HOME"/licenses/android-sdk-license"
      - source environmentSetup.sh && get_android_sdk_25

   cache_directories:
    - /usr/local/android-sdk-linux
    - ~/.android
    - ~/.gradle
   override:
    - ./gradlew dependencies || true

test:
  post:
    - mkdir -p $CIRCLE_TEST_REPORTS/junit/
    - find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;

machine:
    java:
        version: oraclejdk8

Edit: My gradle file :

buildscript {
  repositories {
    jcenter()
    maven {
      url 'https://maven.google.com'
    }
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
    classpath 'com.google.gms:google-services:3.0.0'
    classpath "io.realm:realm-gradle-plugin:3.1.3"
  }
}

allprojects {
  repositories {
    mavenCentral()
    jcenter()
  }
}

task clean(type: Delete) {
  delete rootProject.buildDir
}

15 Answers 15

359

Google have new maven repo

https://android-developers.googleblog.com/2017/10/android-studio-30.html > section Google's Maven Repository

https://developer.android.com/studio/preview/features/new-android-plugin-migration.html https://developer.android.com/studio/build/dependencies.html#google-maven

So add the dependency on maven repo:

buildscript {
    repositories {
        ...
        // You need to add the following repository to download the
        // new plugin.
        google() // new which replace https://maven.google.com
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'  //Minimum supported Gradle version is 4.6.
    }
}
12
  • 2
    if you run intro constraint error use add thse : mavenCentral() jcenter() maven { url 'maven.google.com' } May 21, 2017 at 14:47
  • 4
    You shouldn't need to add mavenCentral(). Because jcenter() shoudl be enough: jfrog.com/knowledge-base/… blog.bintray.com/2015/02/09/…
    – mtrakal
    May 21, 2017 at 22:41
  • I add maven { url 'maven.google.com' } this to gradle script,and build it. I get this error: Gradle sync failed: No route to host How can I resolve this problem
    – yuchangfu
    May 23, 2017 at 8:18
  • 1
    try to open website: maven.google.com in browser, you will see, that it looks like they have error/downtime :/
    – mtrakal
    May 23, 2017 at 10:07
  • 2
    @Parker I am using Android Studio 3.0 - Canary Channel. Here is the top level build.gradle classpath com.android.tools.build:gradle:3.0.0-alpha4, copied as is. Please notice that it is now alpha4 after a update last week
    – sud007
    Jun 27, 2017 at 4:57
108

For things to compile via command line I needed to include the maven repo in BOTH buildscript and allprojects.

root build.gradle:

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
        ...
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

It's needed in the buildscript block to find the AGP, and in allprojects block to find android.arch and com.android.databinding packages (and others)

UPDATE: It looks like the new repo is just called google() but I still needed to declare it in both places.

3
  • 7
    Pay attention to the update: needed to declare it in both places was the solution for me, repositories and allprojects
    – Ultimo_m
    Nov 1, 2017 at 15:48
  • 2
    maven { url 'maven.google.com' } when i place it , it work for me Oct 15, 2019 at 14:32
  • 1
    just replace google() with this -> maven { url 'maven.google.com' } then connect your VPN and sync again. Google makes life tough for Iranians, I wish you the worst google! I really miss Eclipse.
    – Ehsan
    Jan 18, 2021 at 2:59
34

To synchronize all of the answers here and elsewhere:

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

  } }

Make your buildscript in build.gradle look like this. It finds all of them between google and jcenter. Only one of them will not find all of the dependencies as of this answer.

3
  • I had to add this to the allprojects as well and run android/gradlew --stop before trying again. Then it worked.
    – Wayferer
    Nov 7, 2017 at 21:55
  • 2
    I had repositories { jcenter() google() } and it was not working... Reversing the order to repositories { google() jcenter() } fixed the problem
    – ben
    May 28, 2018 at 11:59
  • JCenter Maven repository is no longer receiving updates: Replace with mavenCentral()
    – M Karimi
    Aug 11, 2022 at 10:10
24

For Iranian people: We need use proxy or VPN to building app.

Reason: The boycott by Google's servers causes that you can't build app or upgrade your requirement.

2
  • Can we use offline repository for specific version ?
    – MrSalesi
    Feb 15 at 11:55
  • @MrSalesi ofc not :(
    – A1Gard
    Feb 15 at 23:53
16

mtrakal's solution worked fine.

Added to gradle.build:

buildscript {
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha2'

        // NOTE: Do not place your application dependencies here; 
        // they belong in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Then it automatically upgraded to alpha2.

Invalidate the caches and restarted all is fine.

File | Invalidate Caches / Restart

choose 'Invalidate & Restart'

1
  • JCenter Maven repository is no longer receiving updates: Replace with mavenCentral()
    – M Karimi
    Aug 11, 2022 at 10:11
8

I did this:

click SDk Manager:

enter image description here

Change in updates to Canary Channel, check and update it...

enter image description here

After go in build.gradle and change the compile version to 26.0.0-beta2:

enter image description here

After go in gradle/build.gradle and change dependencies classpath 'com.android.tools.build:gradle:3.0.0-alpha7':

enter image description here

After sync the project... It works to me! I hope I've helped... tks!

7

Make sure you add following line in your top level build.gradle and that should fix it.

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

I got exact same error you mentioned above, once I added this entry everything worked.

2
  • tried and got this : > Could not find com.android.support.constraint:constraint-layout:1.0.2. May 19, 2017 at 17:59
  • I think it would help if you post your app/build.gradle and build.gradle. Also try to use File -> Invalidate Cache optionm restart android studio see if things get better. May 19, 2017 at 20:54
3

For me I solved this error just by adding this line inside repository

maven { url 'https://maven.google.com' }
2

Update: Incredibly frustrating, but the Google redirect of the maven.google.com repo seems to mess with loading the resources. If you instead set your repository to maven { url 'https://dl.google.com/dl/android/maven2' } the files will resolve. You can prove this out by attempting to get the fully qualified resource at https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.pom 3.0.0 Alpha

This is because currently the gradle:3.0.0-alpha1 is only being served via the new 'https://maven.google.com' repository, but the site currently 404s at that location otherwise, being a public directory, you'd see a tree listing of all the files available by simply navigating to that location in your browser. When they resolve their outage, your CI build should pass immediately.

1
1

I find this at google: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

It mentiones that we need to

  1. Update Gradle version to gradle-4.1-all ( changegradle-wrapper.properties by distributionUrl=\https\://services.gradle.org/distributions/gradle-4.1-all.zip
  2. Add google() to repositories repositories { google() } and dependencies { classpath 'com.android.tools.build:gradle:3.0.0-beta7' }

You may require to have Android Studio 3

1
  • I'm not a downvoter, but this doesn't fix the problem because this problem occurs AFTER you actually migrate to new gradle. Oct 31, 2017 at 13:46
1

Android Studio (Preview) sometimes recommends updating to a Gradle Plugin that is not available yet (did Google forget to publish it?). Such as today with

'com.android.tools.build:gradle:3.1.0-beta1'

I found I can see current versions of com.android.tools.build:gradle here, and then I just pick the newest:

https://dl.google.com/dl/android/maven2/index.html

I just found this beta1 gradle bug in the Android Bug Tracker. I also just learned Android Studio > Help Menu > Submit Feedback brought me to the bug tracker.

Found temporary solution at androiddev reddit for the 3.1.0-beta1 problem: Either roll back to Preview Canary 8, or switch to gradle plugin 3.0.1 until Canary 10 is released shortly.

0

My problem was that I forgot that I added a proxy in gradle.properties in C:\Users\(current user)\.gradle like:

systemProp.http.proxyHost=****
systemProp.http.proxyPort=8850
0

I have this problem when update android studio from 3.2 to 3.3 and test every answers that i none of them was working. at the end i enabled Maven repository and its work.

enter image description here

0

Just add this

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

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

It works...Cheers!!!

0

My free advice is simply add mavenCentral() and google() in /build.gradle, or one of them how google advises on the official page. Should be something like this:

allprojects {
...
    repositories {
        mavenCentral()
        ...
        google()
    }
...
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.