Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 256
Alaeddine Bouhajja Avatar asked Nov 30 '21 08:11

Alaeddine Bouhajja


People also ask

Could not received status code 502 from server bad gateway?

Users will come across a 502 bad gateway, often seen as a simple browser message, if the web server received an invalid response from the upstream server it accessed while attempting to fulfill the client's request.


Video Answer


4 Answers

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.

like image 97
Magnus Avatar answered Oct 18 '22 22:10

Magnus


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.

UPD. 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.

like image 44
asmodeoux Avatar answered Oct 18 '22 23:10

asmodeoux


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'
    }
  }
}
like image 25
Sergey Salnikov Avatar answered Oct 18 '22 22:10

Sergey Salnikov


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/
  1. 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.

like image 6
dreambit.io Avatar answered Oct 18 '22 21:10

dreambit.io