Android Studio: Gradle sync failed: Could not HEAD '...'. Received status code 502 from server: Bad Gateway

AndroidAndroid StudioGradleAndroid Gradle-Plugin

Android Problem Overview


After update Android Studio to latest version (3.1) and gradle version in my project I get an error (the link is always different):

12:54	Gradle sync started

12:56	Gradle sync failed: Could not HEAD 'https://jcenter.bintray.com/com/android/tools/analytics-library/shared/26.1.0/shared-26.1.0.jar'. Received status code 502 from server: Bad Gateway 			Consult IDE log for more details (Help | Show Log) (1m 56s 602ms)

12:56	Gradle sync started

12:57	Gradle sync failed: Could not HEAD 'https://jcenter.bintray.com/org/codehaus/mojo/animal-sniffer-parent/1.14/animal-sniffer-parent-1.14.pom'. Received status code 502 from server: Bad Gateway 			Consult IDE log for more details (Help | Show Log) (1m 4s 266ms)

12:58	Gradle sync started

12:59	Gradle sync failed: Could not HEAD 'https://jcenter.bintray.com/com/sun/activation/all/1.2.0/all-1.2.0.pom'. Received status code 502 from server: Bad Gateway 			Consult IDE log for more details (Help | Show Log) (1m 29s 985ms)

13:01	Gradle sync started

13:02	Gradle sync failed: Could not HEAD 'https://jcenter.bintray.com/com/sun/activation/javax.activation/1.2.0/javax.activation-1.2.0.pom'. Received status code 502 from server: Bad Gateway 			Consult IDE log for more details (Help | Show Log) (4s 976ms)

Android Studio version:

Android Studio 3.1
Build #AI-173.4670197, built on March 22, 2018
JRE: 1.8.0_152-release-1024-b02 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

I already tried clean rebuild and update gradle, restart Android Studio and PC, but without success. Any ideas?

PS: of course I have internet. Also, if you open a link in the browser - the file is downloaded.

Android Solutions


Solution 1 - Android

jcenter is having issues at the moment, please check http://status.bintray.com/

EDIT: it looks like the link above was sunset, new link at: https://status.gradle.com/

Solution 2 - Android

>After updating the Android Studio to 3.1.0 ,

I just had the same problem, i resolved it using

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

to the TopMost buildScript like this in project-level gradle :-

 buildscript {
    repositories {
      .....
      ...
     maven {   url "https://maven.google.com"   }

> For reference take a sample of the project-level gradle:-

buildscript {

  repositories {
      google()
      jcenter()
      maven { url 'https://maven.fabric.io/public' }
      maven { url 'https://jitpack.io' }
      mavenCentral()
      maven { url 'https://maven.fabric.io/public' }
      maven {  url "https://maven.google.com"  }
  }
 dependencies {
     classpath 'com.android.tools.build:gradle:3.1.0'
     classpath 'io.fabric.tools:gradle:1.24.4'
   }
}

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

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

Note :- One more thing:-

In gradle-wrapper.properties use this :-

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

Instead of 4.1-all.zip .

Edit :- If you want to resolve the issue fast , you can also try adding these - according to Omar's answer :-

 maven { url "http://dl.bintray.com/riteshakya037/maven" }

along with

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

Solution 3 - Android

Thanks to everyone for the quick answers!

It seems like temporary network issues on the "jcenter.bintray.com" website. I just clicked "Try Again" many times and in the end everything was updated.

Also, if you open the links in the browser - from time to time you will receive a "Service Error" message. So the problem is not on your side.

Solution 4 - Android

Ok, I slove it by:

In your build.gradle project level, add this:

buildscript {
    ...
repositories {
    google()
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'https://jitpack.io' }
    mavenCentral()
    maven { url "https://maven.google.com" }
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.0' // Updated from 3.0 to 3.1.0

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

Note that I've updated gradle from 3.0 to 3.1.0

Next: add the same previous links to allprojects's repository body:

allprojects {
repositories {
    google()
    jcenter()
    mavenCentral()
    maven { url 'https://jitpack.io' }
    maven { url "https://maven.google.com" }
    maven { url 'https://maven.fabric.io/public' }
}

}

One more thing:

In gradle-wrapper.properties use this :

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

After that, just sync again, and it will work.

Solution 5 - Android

Tip:
When you get your project to build correctly the once enable offline-mode so AS don't have to connect to jcenter every gradle refresh.

enter image description here

Solution 6 - Android

For me after applying Santanu Sur's answer The error hapenned again but with another library I have check project's gradle and I found this line maven { url "http://dl.bintray.com/riteshakya037/maven" } in

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/riteshakya037/maven" }
        maven { url "https://jitpack.io" }
        jcenter()
        google()
    }
}

I deleted it, and everything is good now

Solution 7 - Android

I've just clicked Disable Gradle 'offline mode' and sync project and Android Studio downloaded all the needed files.

Solution 8 - Android

It's a server response error. Keep trying by pressing "Try Again" after some time. It will be ok automatically.

Solution 9 - Android

Uninstalling and Download & install from Developer site solved the issue for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMikhailView Question on Stackoverflow
Solution 1 - AndroidGustavoView Answer on Stackoverflow
Solution 2 - AndroidSantanu SurView Answer on Stackoverflow
Solution 3 - AndroidMikhailView Answer on Stackoverflow
Solution 4 - AndroidPedro MassangoView Answer on Stackoverflow
Solution 5 - AndroidhumazedView Answer on Stackoverflow
Solution 6 - AndroidOmar HossamEldinView Answer on Stackoverflow
Solution 7 - AndroidunipinView Answer on Stackoverflow
Solution 8 - AndroidSahidul Hassan RazonView Answer on Stackoverflow
Solution 9 - Androiduser1831682View Answer on Stackoverflow