Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 3.1.4 Gradle Sync Failed

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)

like image 659
HF_ Avatar asked Aug 11 '18 07:08

HF_


People also ask

Why is my gradle not syncing?

For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.

How do I sync gradle with Android Studio?

Open your gradle. properties file in Android Studio. Restart Android Studio for your changes to take effect. Click Sync Project with Gradle Files to sync your project.


1 Answers

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!

like image 134
HF_ Avatar answered Oct 07 '22 09:10

HF_