22

I'm forcing gradle to use http I have modified my gradle-wrapper.properties:

distributionUrl=http\://services.gradle.org/distributions/gradle-4.3-all.zip

The build.gradle:

buildscript {
repositories {
    //jcenter()
    //google()
    maven { url "http://jcenter.bintray.com"}     
    }
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'

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

allprojects {
repositories {
    jcenter()
    maven { url 'http://maven.google.com' }
    maven { url "http://jitpack.io" }
}}

As far as I'm aware I should use 3.0.1 but when I check the actual repo on jitpack or maven only up to 2.3.3 is available.

The error message I'm getting is:

> Could not resolve all files for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:3.0.1.
Searched in the following locations:
http://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
http://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
Required by:
     project :* Try:

Gradle version is 4.3.1 JVM 9.0.1

What can be done to successfully run 'gradle test' here?

EDIT: uncommenting //google() reveled:

       > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'.
        > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'.

When modified the http repo

buildscript {
repositories {
    //jcenter()
    //google()
    maven { url "http://jcenter.bintray.com"}
    maven { url "http://maven.google.com"}

    }

I got:

      > Could not resolve com.android.tools.build:gradle:3.0.1.
     > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'.
        > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'.
           > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  > Could not resolve com.android.tools.build:gradle:3.0.1.
     > Could not get resource 'http://maven.google.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'.
        > Could not GET 'http://maven.google.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'.
           > sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I get the same if I uncomment both jcenter() and google(). Besides, when I check https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/ the link is dead. Now the jcenter repo https://repo1.maven.org/maven2/com/android/tools/build/gradle/ ends on 2.3.3 version which seems to be correct that this error is happening, the question is what is wrong then?

EDIT- Likely solution the issue happenned because you can't run those excluding https completely, it will fail either way.

kol23
  • 1,498
  • 3
  • 16
  • 35
  • 1
    Check this [link](https://developer.android.com/studio/releases/gradle-plugin.html) your android studio must compatible with gradle version – yashkal Jan 16 '18 at 08:29
  • 1
    try with uncomment **//google()** in build file – Omkar Jan 16 '18 at 08:33
  • ok although this is not in android studio but in the command line. I'll uncomment it – kol23 Jan 16 '18 at 08:34
  • If @Omi 's advice won't help try to uncomment //jcenter as well. – AloDev Jan 16 '18 at 08:37
  • 1
    just tried as the below answer by IntelliJ Amiya suggested, Getting the same > Could not get resource 'http://maven.google.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'. – kol23 Jan 16 '18 at 08:43
  • There must be a problem with some kind of proxy. Check this out: https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000094584/comments/115000405564 – R. Zagórski Mar 08 '18 at 16:29
  • try adding google() to allprojects.repositories while uncommenting also in the buildscript.repositories and remove the maven dependencies – emirua Mar 09 '18 at 00:03
  • Are you trying to build under a proxy? – sanoop sandy Mar 14 '18 at 09:36
  • You're last stack trace is stating that `dl.google.com` is not a trusted host, but that can't be unless if a certain proxy is doing some SSL offloading on behalf of it and providing a fake SSL certificate when undergoing the handshake. If your unaware of a proxy please be careful as this could mean a man in the middle attack. With regards to the repo's, all of them seem to provide the artifacts over https and no loner http any more, try jitpack for example it will always redirect http to https. – ahasbini Mar 15 '18 at 00:09
  • are you on company's network. Because most of the company's firewall is blocking this. – KKSINGLA Mar 15 '18 at 06:00
  • in your gradle properties add this `android.enableAapt2=false` – Hemant Parmar Mar 15 '18 at 11:08
  • use this link https://stackoverflow.com/questions/51797446/android-studio-3-1-4-gradle-sync-failed – Engineer Rasul Shamohamadi Apr 05 '19 at 16:36

12 Answers12

8

Could not resolve com.android.tools.build:gradle:3.0.1.

Read Google's Maven repository

Include Google's Maven repository in your top-level build.gradle file:

FYI

allprojects {
    repositories {
        google()

        // If you're using a version of Gradle lower than 4.1, you must instead use:
        // maven {
        //     url 'https://maven.google.com'
        // }
        // An alternative URL is 'https://dl.google.com/dl/android/maven2/'
    }
}

So, According to your version your build.gradle will

buildscript 
{

    repositories {
        jcenter()
        google()
        maven { url "http://jcenter.bintray.com"}     
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

    }
}

allprojects 
{
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • I have edited my answer, tried this exact setup and produced the same error, Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom'. – kol23 Jan 16 '18 at 08:41
  • @koller23 Kindly Restart IDE and gradle – IntelliJ Amiya Jan 16 '18 at 08:46
  • Besides I can't use https this time, Regarding IDE this is only command line like gradle test, fastlane test etc. – kol23 Jan 16 '18 at 08:46
  • 1
    @koller23 add `allprojects { repositories { jcenter() maven { url "https://jitpack.io" } maven { url 'https://maven.google.com/' } google() } }` – IntelliJ Amiya Jan 16 '18 at 08:55
  • I can't use https. Tried http. After stopping gradle daemon and adding the above > Could not resolve all files for configuration ':classpath'. > Could not find com.android.tools.build:gradle:3.0.1. Searched in the following locations: http://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom http://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar – kol23 Jan 16 '18 at 08:59
  • @koller23 Kindly check this link https://stackoverflow.com/questions/47515676/gradle-4-1-issue-on-latest-android-studio-3-0-1 – IntelliJ Amiya Jan 16 '18 at 09:01
  • added android.enableAapt2=false to gradle.properties. Pretty much the same output – kol23 Jan 16 '18 at 09:03
  • unfortunately this didn't work either for 4.1 it says that there is an issue with java 9.0.1 on gradle test execution while on 4.3 crashes on no item in repo – kol23 Jan 16 '18 at 12:58
5

I got the same issue and i solved it by making changes main gradle file, as per suggestion given by android studio

buildscript {
    repositories {
        jcenter()

        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

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

gradle-wrapper.properties :

distributionUrl=  https\://services.gradle.org/distributions/gradle-4.1-all.zip

my gradle file is like this, make like this in you project it would most probably work.

Thank you.

Sagar
  • 554
  • 5
  • 21
3

What worked for me was to remove jcenter() and revert Gradle to an earlier version.

Unfortunately the latest stable version in bintray is 2.3.3 , but atleast I was able to build successfully.

My build.gradle now looks like this:

buildscript {
    repositories {
        maven { url "http://jcenter.bintray.com"}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'

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

allprojects {
    repositories {
        maven { url "http://jcenter.bintray.com"}
    }
}
Hristo Stoyanov
  • 1,960
  • 1
  • 12
  • 24
3

Try this and make sure your network works well (no proxy ...) :

in gradle-wrapper.properties :

distributionUrl=  https\://services.gradle.org/distributions/gradle-4.1-all.zip

and in build.gradle:

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

allprojects {
    repositories {
        jcenter()
        google()
    }

}
MrZ
  • 560
  • 2
  • 12
2

Add following code into your app level gradle file.

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        maven { url "http://jcenter.bintray.com"}
        maven { url "http://maven.google.com"}
}
1

Not sure but your this error Could not resolve all files for configuration ':classpath'. When your path is not set so Follow below step:

Go to the File -> Setting -> Version Controller

Then you Change VCS to < None >

see below image :

enter image description here

Ali
  • 3,346
  • 4
  • 21
  • 56
1

I got the same issue because I used to set proxy(no proxy now) and click the OK button in proxy setting, so, check the following:

  1. echo $proxy(mac)
  2. /user/XXX/.gradle/gradle.properties

    # systemProp.https.proxyPort=1080
    # systemProp.http.proxyHost=127.0.0.1
    # systemProp.https.proxyHost=127.0.0.1
    # systemProp.http.proxyPort=1080
    
  3. project/gradle.properties

gmyboy
  • 81
  • 1
  • 7
1

I had the same problem, for solving it I did the following

1- install android studio with required SDKs

2- set manual proxy in android studio: File > Settings > Appearance & Behavior > System Settings > HTTP Proxy

3- In android studio click on Gradle icon, to sync project with gradle files. Then

4- while android studio and proxy are active, in command prompt by running this command "ionic cordova build android" (I was using ionic platform), it will download all requirement gradle libraries and packages.

Alexandre Elshobokshy
  • 10,720
  • 6
  • 27
  • 57
a1i
  • 43
  • 1
  • 7
0

Check that you don't filter Google IPs.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
0

This worked for me, I needed to install google dependencies

enter image description here

0

Another explanation is VPN. When my work's VPN is ON, on my Mac, I get this error. When off, I don't. Could be something particular to my VPN's configuration. So, if you have a VPN running, try disabling it turning the build.

ncr100
  • 58
  • 10
0

I had problems with the snap version of gradle in my GNU/Linux distribution.

I fixed with:

sudo snap remove  gradle
sudo apt  install gradle
Valerio Bozz
  • 1,176
  • 16
  • 32