Could not GET 'play-services-location/maven-metadata.xml'. Received status code 502 from server: Bad Gateway
Asked Answered
K

19

53

I have a project which was running well yesterday, but today I find this problem:

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not resolve com.google.android.gms:play-services-location:16.+. Required by: project :app > project :location > Failed to list versions for com.google.android.gms:play-services-location. > Unable to load Maven meta-data from https://google.bintray.com/exoplayer/com/google/android/gms/play-services-location/maven-metadata.xml. > Could not get resource 'https://google.bintray.com/exoplayer/com/google/android/gms/play-services-location/maven-metadata.xml'. > Could not GET 'https://google.bintray.com/exoplayer/com/google/android/gms/play-services-location/maven-metadata.xml'. Received status code 502 from server: Bad Gateway

Actually I'm using classpath 'com.android.tools.build:gradle:4.1.0'with distributionUrl=https://services.gradle.org/distributions/gradle-6.5-bin.zip.

I have followed this question and upgraded 'com.android.tools.build:gradle:4.1.0' to classpath 'com.android.tools.build:gradle:4.2.0'.

Then I changed distributionUrl=https://services.gradle.org/distributions/gradle-6.5-bin.zip to distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip but I still got the error.

android/build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
    }

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

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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

Also I have changed the compileSdkVersion , minSdkVersion and targetSdkVersion to be 30 but nothing happened.

Kohlrabi answered 30/11, 2021 at 8:58 Comment(3)
It seems to be working now, is it working for you as well? If it is, consider accepting the answer from asmodeoux since it seems that it was in fact a temporary issue.Candi
the server sees to be permanently removed :(Dylan
guys U can turn of your internet so you can use your packages in offline mode. U didn't have to connect with the binary server.Kohlrabi
C
39

The problem is that a plugin (location in this case) didn't specify a fixed version of an Android library. So in order to find which versions are available, Gradle must go to the repository to check. In this case, that repository is Bintray, which has been down for days and returning HTTP 502 Bad Request.

The steps below provide a quick and dirty workaround so you can build the app while Bintray is down. A more proper solution would be to fork the plugin and make changes to your fork as suggested by Eldar Miensutov, but it might be a bit overkill for a temporary server error.

  1. In the Project tool window (where your files are listed), scroll all the way down until you find Flutter Plugins. If you don't see it, make sure that Project is selected in the dropdown at the top of the Project tool window.
  2. Open Flutter plugins, find location-4.0.0 and open it (you might have a different version number after location-, that's fine).
  3. Open the file location-4.0.0/android/build.gradle
  4. Find the line api 'com.google.android.gms:play-services-location:16.+'
  5. Change it to api 'com.google.android.gms:play-services-location:16.0.0'. If your editor says that the file does not belong to your project, select "I want to edit this file anyway".

You should now be able to build the app.

This change is of course a temporary solution, and if you update the location plugin your changes will be overwritten. But at least you'll be able to build until Bintray comes online again (or until you had time to migrate to another more recently updated plugin).

OR

In case the problem is caused by the location plugin and you are able to update to the latest version of it (4.3.0 at the moment), that also seems to resolve the problem. In my case, I was stuck on an old version of Flutter and location because of some other packages that weren't compatible with Flutter 2.

Candi answered 11/12, 2021 at 23:42 Comment(2)
Hello @Magnus. I'm having a similar issue, but in my case it's happening with the Firebase libraries. -- For example, the error I'm getting is related to the firebase_analytics library. But let's say I remove that library from my project, then I get a similar error for the cloud_firestore library (which is much harder to remove in my case) -- Do you have an idea of could I do to fix this issue for me? -- BTW: I'm using Flutter v2.0.3, old versions of the library (which I have tried to upgrade but it's too much work right now) and Dart without sound null-safetyDisarming
My location is 4.3.0 but it also use api 'com.google.android.gms:play-services-location:16.+' in its build.gradleBranen
R
16

It looks like a temporary issue, the server with these libraries is down. I have the same problem now with Room:

Could not GET 'https://google.bintray.com/exoplayer/androidx/room/room-common/maven-metadata.xml'. Received status code 502 from server: Bad Gateway

You can try using offline mode if you're using Android Studio, then it will use the cached version of this library if you have it until it is fixed.

I switched to an alpha version of a flutter lib which caused this (workmanager) and it works well now. As far as I understand it was depending on an old version of Android Room library which is not available anymore since Bintray is not available. The new version of Room is available as it's being downloaded thorough another link. So for you the solution could be updating to a newer version of Flutter location package or forking it and changing the version of play-services-location to the most recent one.

Reader answered 30/11, 2021 at 9:29 Comment(5)
Same here, but it works if I use targetSdkVersion and compileSdkVersion 29 instead of 30. Not sure if it's my configuration that's wrong or is anyone else still experiencing this issue with the bintray URL? status.bintray.com shows nothing. But it says bintray is deprecated - so is there any way to force the build to use some other URL?Candi
@Candi for me it still doesn't work, and changing both target & compile versions doesn't fix it as well...Reader
@Reader Thanks for the update. I think maybe the reason why SDK version 29 works for me is because I built with it yesterday, so maybe it got cached locally. But today I had to upgrade to SDK version 30 because Google Play requires it to publish an update...Candi
Hi I would like to ask, it is fine when I am running my project in debug mode, but getting the same error like @AlaeddineBouhajja when I do flutter build apk in release mode. So I just need to wait a little bit longer right because of 502 error ?Snubnosed
I'm also having this issue again... it seems that server is very unstable recently, I got the error yesterday as well but then it started working, and now it's not working again. All these answers saying replace jcenter() with mavenCentral()/etc don't seem to work for me, the error persists until the URL in the error message comes back online. There's got to be some way to force gradle to use another URL somehow, but how? And turning off wifi doesn't work either, it gives me another gradle-related error message and stops the build immediately.Candi
D
12

Main problem that location:3.2.4 has no strict Android dependecy version play-services-location:16.+

Straight way to workaround this problem is to add Gradle Constraints on transitive dependency and specify concrete version in app/build.gradle

Updated from comment. You don't need to modify dependency package or lib, you have to edit your project file app/build.gradle

dependencies {
...
  constraints {
    implementation('com.google.android.gms:play-services-location') {
        version {
            strictly "16.0.0"
        }
        because 'location: 3.2.4 does not specify version & google.bintray.com answers 502 Bad Gateway'
    }
  }
}
Dogwatch answered 15/12, 2021 at 8:41 Comment(0)
C
6

If you meet this issue with play-services-location under the location flutter package you can proceed with the next solution:

  1. Do a fork of the repository flutterlocation

  2. Do changes in the forked project. (All the changes you can check in this commit)

  3. Commit it. Push it

  4. In your project change the way you get the dependency from your forked library

    location:
      git:
        url: git://github.com/dreambitio/flutterlocation.git
        ref: release/3.2.4
      path: location/
    
  5. Done

Few notes

  • If version 3.2.4 works for you, you can just go with step 4

  • Assume this scenario works for any other library. Fork->Hotfix->Change target

  • Yeah, that's not a nice solution, but should allow you to proceed locally or with any CI tool.

Colon answered 12/12, 2021 at 22:23 Comment(1)
Hello what does this mean "In your project change the way you get the dependency from your forked library" ? How I add the dependency in my project? Thank youJocelin
S
4

For anyone who cannot find the folder in @Magnus's answer, you can open the file in path like

C:\flutter\.pub-cache\hosted\pub.dartlang.org\location-4.1.1\android\build.gradle

then change

api 'com.google.android.gms:play-services-location:16+'

to

api 'com.google.android.gms:play-services-location:16.0.0'
Salita answered 26/1, 2022 at 8:13 Comment(0)
H
2

After hours of debugging. I fixed the build just by removing the old pubspec.lock file and updating the firebase_messaging from ^9.1.4 to ^11.1.0. I don't know why I don't know how this fixed the issue.

It seems something relating to dependencies.

I found the problematic dependency by running flutter run --verbose and analyzing the output.

Heiser answered 30/11, 2021 at 18:29 Comment(4)
I didn't use any dependency from firebaseKohlrabi
In my case work manager library causes it, but I already use the latest version of it, so it's not my caseReader
Try removing the pubspec.lock and run flutter build it will generate new pubspec as the package manager will get fresh dependencies which mb do not rely on jcenter() I found the problematic dependency by running flutter run --verbose and analyzing the output.Heiser
The bintray server is back upHap
W
2

For those having the issues, it seems that the Bintray server is down recently. My temporary fix for it is to switch the Gradle build to be offline to use the caches to build the app.

Go to android -> gradlew.bat and modify the following and rebuild your app :

@rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% --offline

Wakefield answered 10/12, 2021 at 7:19 Comment(2)
This approach fails in CI/CD in pipelines...Dylan
This sounded promising, but unfortunately I couldn't get it to work with this workaround either. Any way to check what's in the gradle cache?Candi
K
2

If you already have the packages, you can turn off your internet so that you can use the packages in offline mode; this is a solution to debug your apps until the server is back.

Kohlrabi answered 10/12, 2021 at 14:12 Comment(0)
T
1

For React-Native developers, try to replace

maven { url 'https://google.bintray.com/exoplayer/' }

by

maven { url 'https://dl.google.com/dl/android/maven2'}

in project level build.gradle

Theda answered 12/12, 2021 at 9:27 Comment(0)
C
1

just change the distributionUrl in gradle-wrapper.properties to

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

it works for me.

Capillaceous answered 28/12, 2021 at 10:28 Comment(0)
I
1

You can resolve this issue by the following steps,

  • Change the build.gradle file as below,
  • Change the kotlin version to 1.4.0 or higher
  • Remove jcenter() from repositories and add mavenCentral()
  • Change build gradle tools version to 4.1.0 or higher
 buildscript {
    ext.kotlin_version = '1.4.0' // or higher
    repositories {
        google()
        mavenCentral()  // add this
        maven {
            url 'https://maven.google.com'
        }
        // jcenter()  //remove or comment this
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'  // or higher
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()  // add this
        maven {
            url 'https://maven.google.com'
        }
        // jcenter()  // remove or comment this
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  • Change the gradle distribution version on gradle-wrapper.properties file to 6.7 or higher
#Fri Mar 23 08:50:38 IST 2022
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
  • Upgrade the dependencies by the following command
flutter upgrade
  • Done.
Ironbark answered 28/3, 2022 at 7:2 Comment(0)
B
1

I got a simple solution for this, it's working for me. It's not a very big change very small change. Increase the SDK version and all, just see below

    android {
        compileSdk 32
    
        defaultConfig {
            applicationId "com.example.abc"
            minSdk 21
            targetSdk 32
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
}
Babism answered 3/8, 2022 at 11:40 Comment(0)
B
0

This is usually solved by updating the gradle distribution in your gradle.wrapper.properties file. At least this is what worked for me (also solved CI/CD pipeline issue after this)

So i updated to :

distributionUrl=https://services.gradle.org/distributions/gradle-6.8.3-all.zip
Blackbird answered 13/12, 2021 at 14:49 Comment(0)
C
0

enter image description here

After spending a week, i finally find out a temporary solution. On left side of VS code expand dependencies option and go to location and on the build.gradle file change the line as in the picture.

Crankpin answered 14/12, 2021 at 16:50 Comment(2)
Hey, but where would you add this. In the build.gradle of the package or your project? –Disarming
This answer has straight dependency, you need just constrain transitional dependency version. Check this https://mcmap.net/q/338520/-could-not-get-39-play-services-location-maven-metadata-xml-39-received-status-code-502-from-server-bad-gatewayDogwatch
U
0

upgrading 'com.google.android.gms:play-services-ads-identifier:16+' plugin resolved me

Goto build.gradle(app) and change to latest version

   implementation 'com.google.android.gms:play-services-ads-identifier:18.0.1'
Unstopped answered 12/1, 2022 at 19:21 Comment(0)
L
0

I had run into the same problem, did some workaround and it worked. In your android/build.gradle:

  • change the kotlin version to ext.kotlin_version = '1.5.0'
  • change android gradle version to: classpath 'com.android.tools.build:gradle:4.1.0'

Then go to android/gradle/wrapper/gradle-wrapper.properties and change distributionUrl to 6.9 like this:

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

Then flutter clean and run. :D

Lobar answered 31/1, 2022 at 11:53 Comment(0)
H
-1

If you use gradle implementation(you may not use implementation, but visitors for this question may use), I could solve 502 problem like below.

implementation 'com.xxx.yyy:a.b.c' // not use +

before script I wrote(502 problem occured)

implementation 'com.xxx.yyy:a.b.+' // use +
Hypothyroidism answered 12/12, 2021 at 3:18 Comment(0)
L
-1

You can try running the app without internet connection but it is not a permanent solution. Because without internet you can't build apk file.

Try this, it resolved my issue.

project level gradle file

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        mavenCentral() // <- replaced jcenter()
    }

dependencies {
    classpath 'com.android.tools.build:gradle:4.+' // <- updated this
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.3.10'
    classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
    }

}

allprojects {
    repositories {
        google()
        mavenCentral() // <- replaced jcenter()
    }
}

also, on gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip // <- updated this
Lift answered 14/12, 2021 at 2:48 Comment(0)
B
-2

I got this 502 error " bad gateway https://kotlin.bintray.com/kotlinx/androidx/room/room-common/maven-metadata.xml" when trying to run this codelab in Android Studio: https://github.com/google-developer-training/android-kotlin-fundamentals-apps/tree/master/DevBytesRepository

I fixed it by making the following changes in the "build.gradle(Project:DevBytesRepository) file:

1 - Add repository mavenCentral()

2 - remove jcenter() repository

3 - Remove maven { url "https://kotlin.bintray.com/kotlinx/" } as per below:

buildscript {
ext.kotlin_version = '1.3.72'
repositories {
    google()
    mavenCentral()
    //jcenter()
}
allprojects {
    repositories {
        google()
        mavenCentral()

      //  maven { url "https://kotlin.bintray.com/kotlinx/" }
    }  
Bravo answered 11/12, 2021 at 7:29 Comment(1)
I tried it before and it didn't work. What does work for me is this answer.Candi

© 2022 - 2024 — McMap. All rights reserved.