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
}
Mohamed ALOUANE
  • 5,349
  • 6
  • 29
  • 60

15 Answers15

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.
    }
}
mtrakal
  • 6,121
  • 2
  • 25
  • 35
  • 2
    if you run intro constraint error use add thse : mavenCentral() jcenter() maven { url 'https://maven.google.com' } – Mohamed ALOUANE May 21 '17 at 14:47
  • 4
    You shouldn't need to add `mavenCentral()`. Because `jcenter()` shoudl be enough: https://www.jfrog.com/knowledge-base/why-should-i-use-jcenter-over-maven-central/ https://blog.bintray.com/2015/02/09/android-studio-migration-from-maven-central-to-jcenter/ – mtrakal May 21 '17 at 22:41
  • I add maven { url 'https://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 '17 at 08:18
  • 1
    try to open website: https://maven.google.com in browser, you will see, that it looks like they have error/downtime :/ – mtrakal May 23 '17 at 10:07
  • @sud007 - How'd you know the latest is 3.0.0-alpha3? I can't find references for anything past alpha1, and the maven search sites only show 2.x – Parker Jun 26 '17 at 20:50
  • 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 '17 at 04:57
  • @sud007 oh man, I didn't make the connection that the Gradle and Android studio are the same version. Thanks! – Parker Jun 27 '17 at 04:59
  • `url 'maven.google.com';` is now replaced with `google()` so please update: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#apply_plugin – mtrakal Jul 03 '17 at 08:10
  • I removed 'maven.google.com' from buildscript and allprojects, and only add google() on allprojects, and my problem gets fixed. thank you! – Oscar Josue Alvrez Nov 15 '17 at 16:59
  • This should be edited in the build.gradle of the **Project** (not app level) – chenop Dec 16 '17 at 22:12
  • I have to use `url "https://maven.google.com"` to migrate to 3.0.0, then I can use `google()`. – Kimi Chiu Jan 13 '18 at 03:33
  • We will never have a PERMANENT STANDARDS for this; Gosh, every day a changing !! :-/ and remember that Rep. **google()** is for Gradle 4.1 and up – PYK Jul 08 '19 at 15:14
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.

tir38
  • 9,810
  • 10
  • 64
  • 107
  • 7
    Pay attention to the update: *needed to declare it in both places* was the solution for me, repositories and allprojects – Ultimo_m Nov 01 '17 at 15:48
  • 2
    maven { url 'https://maven.google.com' } when i place it , it work for me – Faisal Ashraf Oct 15 '19 at 14:32
  • 1
    just replace google() with this -> maven { url 'https://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 '21 at 02: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.

GenericJam
  • 2,915
  • 5
  • 31
  • 33
  • I had to add this to the `allprojects` as well and run `android/gradlew --stop` before trying again. Then it worked. – Wayferer Nov 07 '17 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 '18 at 11:59
  • JCenter Maven repository is no longer receiving updates: Replace with mavenCentral() – M Karimi Aug 11 '22 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.

A1Gard
  • 4,070
  • 4
  • 31
  • 55
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'

NOTiFY
  • 1,255
  • 1
  • 20
  • 36
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!

Douglas
  • 479
  • 4
  • 7
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.

Subodh Nijsure
  • 3,305
  • 5
  • 26
  • 45
  • tried and got this : > Could not find com.android.support.constraint:constraint-layout:1.0.2. – Mohamed ALOUANE May 19 '17 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. – Subodh Nijsure May 19 '17 at 20:54
3

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

maven { url 'https://maven.google.com' }
manar odeh
  • 111
  • 3
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.

BrandonJF
  • 33
  • 6
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

Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173
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.

arberg
  • 4,148
  • 4
  • 31
  • 39
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
mohas
  • 1,911
  • 1
  • 16
  • 20
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

A Mo
  • 153
  • 8
0

Just add this

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

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

It works...Cheers!!!

DaveAAA
  • 740
  • 7
  • 14
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()
    }
...
}
Iefimenko Ievgen
  • 379
  • 1
  • 5
  • 12