Android Studio 3.1.4 Gradle Sync Failed
Asked Answered
L

7

9

Whenever I create a new project in Android Studio it fails at Gradle Sync and always the same error:

Connection timed out: connect

org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.4/gradle-3.1.4.pom'.

A screenshot of the IDE:

It fails exactly when GET this link: https://jcenter.binary.com/com/android/tools/build/gradle/3.1.4/gradle-3.1.4.pom, but it can receive other links like dl.google.com and SDK Manager. I was getting this error even on AS 3.1.3 and I haven't ever been able to create an Android Application by Android Studio. It can be done easily by Eclipse ADT, but I wanna use Android Studio because it's the official IDE for Android and Google is supporting Android Studio.

Any way to solve this boring failure of Gradle? (I already searched one thousand times at Google and Stack overflow)

Lenette answered 11/8, 2018 at 7:21 Comment(6)
try setting http proxy in Android studio and use vpnDurmast
I tried that already. Please note that I said: "but it can receive other links like dl.google.com and SDK Manager".Lenette
@هادیفرید Check my answer, you'll sometimes need to Invalidate Caches and reopening Android Studio.Cupriferous
What does exactly PLEASE DON'T EDIT MY POST :) means btw?Cupriferous
What is your Gradle distribution url?Mella
Can post your build.gradle?Vernellvernen
L
19

Finally it worked!

UPDATE (Best Answer)

JCenter detects most VPNs, I have a better solution for you (Iranian developers):

There is a service that helps us to pass restrictions (like JCenter, Android Developer, and so many services): https://shecan.ir (شکن), you can use that fast service without disconnection or other headaches (it uses DNS to bypass restrictions, so usually faster than VPN).

Old Answer

Dear Iranian Developers, you can easily solve this problem with these simple steps:

1 - Turn on the Psiphon

2 - In the Psiphon (VPN) go to Settings -> Local Proxy Ports -> HTTP, HTTPS: 63620 - SOCKS: 63621. This will force the Psiphon to always use port 63620 for HTTP.

3- Go to AS Settings -> Appearance & Behavior -> System Settings -> HTTP Proxy -> Manual proxy configuration -> HTTP: Host name: 127.0.0.1 - Port: 63620 -> Uncheck Proxy Authentication.

Note: These ports (63620, 63621) are custom, but the HTTP port of the Psiphon and the AS HTTP Proxy Settings must be the same.

4 - Note: Android Studio works online only the first time you create the project. After that, you can work offline and build your project or sync it again with Gradle.

Done!

Lenette answered 12/8, 2018 at 5:53 Comment(1)
Not working. Also, I am not sure that it's safe to use Iranian dns servers =(Tarton
M
3

Of course, link is blocked by our (Iranian IPs) so, the idea is to enable VPN then reopening Android Studio and if it couldn't download it again, Invalidate Caches/Restart :

(Android Studio -> File -> Invalidate Caches/Restart)

then you should be good to go.

This also could happen for adding a Library in Gradle.build which can be bypassed by this method.

Mandel answered 11/8, 2018 at 7:30 Comment(5)
I already enabled VPN and HTTP Proxy and it can connect to developer.android.com... My problem is jcenter.Lenette
Android Studio -> File -> Invalidate Caches/Restart. No Changes :(Lenette
This also happens when a VPN have a problem or don't know, can't get connected to that server. Maybe OpenVPN can help.Cupriferous
Master, my VPN works perfectly and Android Studio can connect to Servers which is restricted our country.Lenette
I have tried the Invalidate Caches but with the same error. And I'm not using any proxies as I'm connecting directly to the internet.Lauren
B
1

I also faced this issue after updating Android Studio.

I resolved it by downgrading the version of com.android.tools.build:gradle in project level build.gradle file same like old projet.

1> Open your another project

-------Check version of com.android.tools.build:gradle in Project level gradle

-------Check distributionUrl version in gradle-wrapper.properties

2> Apply both these version in your project

Project level build.gradle

buildscript {
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1' // your version

gradle-wrapper.properties

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

Sync and run, All errors gone!

Birthmark answered 24/8, 2018 at 7:53 Comment(0)
S
1

go to address https://github.com/clarketm/proxy-list select one proxy and port

Go to AS Settings -> Appearance & Behavior -> System Settings -> HTTP Proxy -> Manual proxy configuration -> HTTP: Host name: ip - Port: port ->check Proxy Authentication check adress https://developer.android.com/studio/ if ok end

Supernatural answered 25/8, 2018 at 14:3 Comment(0)
I
1

use Hotspot Shield

I faced the same problem because this service is banned in Syria

Isaac answered 8/1, 2021 at 21:53 Comment(1)
This should go as a comment.Haas
F
0

I had the same problem and update the gradle version to the last one:

Old

classpath 'com.android.tools.build:gradle:3.1.3'

New

classpath 'com.android.tools.build:gradle:3.1.4'

And it worked correctly.

Favourable answered 26/9, 2018 at 8:29 Comment(0)
H
0

In my case, I need to add the google()

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
    }
}
Harp answered 11/12, 2018 at 16:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.