无法获取'play-services-location/maven-metadata.xml'。服务器返回状态码502:坏的网关。

52

我有一个项目,昨天一直正常运行,但今天我发现了这个问题:

无法解析配置“:app:debugRuntimeClasspath”的所有文件。 无法解析 com.google.android.gms:play-services-location:16.+。 需要此依赖项: project :app > project :location > 列出 com.google.android.gms:play-services-location 的版本失败。 > 无法从https://google.bintray.com/exoplayer/com/google/android/gms/play-services-location/maven-metadata.xml加载 Maven 元数据。 > 无法获取资源'https://google.bintray.com/exoplayer/com/google/android/gms/play-services-location/maven-metadata.xml'。 > 从服务器接收状态代码502:Bad Gateway

实际上我正在使用 classpath 'com.android.tools.build:gradle:4.1.0'distributionUrl=https://services.gradle.org/distributions/gradle-6.5-bin.zip

我遵循了这个问题并将 'com.android.tools.build:gradle:4.1.0' 升级到了 classpath 'com.android.tools.build:gradle:4.2.0'

然后我将 distributionUrl=https://services.gradle.org/distributions/gradle-6.5-bin.zip 改为 distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip 但我仍然遇到错误。

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

另外,我已将 compileSdkVersionminSdkVersiontargetSdkVersion 更改为 30,但没有任何变化。

Translated text:

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


现在似乎正在工作,对你来说也是这样吗?如果是的话,考虑接受asmodeoux的答案,因为实际上这似乎是一个暂时性问题。 - Magnus
1
服务器似乎已经永久移除 :( - Marcello DeSales
各位可以关闭网络,这样就可以在离线模式下使用您的软件包。您不必连接二进制服务器。 - Alaeddine Bouhajja
19个回答

39
问题在于一个插件(本例中是location)没有指定一个固定版本的Android库。因此,为了找到可用的版本,Gradle必须去仓库检查。在这种情况下,该仓库是Bintray,它已经停机数天,并返回HTTP 502 Bad Request
以下步骤提供了一个快速而简单的解决方法,让您可以在Bintray停机时构建应用程序。更好的解决方案是根据Eldar Miensutov的建议分叉插件并对其进行更改,但这可能有点过度杀手对于临时服务器错误。
  1. 在项目工具窗口(列出文件的窗口)中,向下滚动直到找到Flutter Plugins。如果您没有看到它,请确保在项目工具窗口顶部的下拉菜单中选择Project
  2. 打开Flutter plugins,找到location-4.0.0并打开它(您可能在location-后面有不同的版本号,这没关系)。
  3. 打开文件location-4.0.0/android/build.gradle
  4. 找到行api 'com.google.android.gms:play-services-location:16.+'
  5. 将其更改为api 'com.google.android.gms:play-services-location:16.0.0'。如果您的编辑器说该文件不属于您的项目,请选择"我仍然想要编辑此文件"
现在,您应该能够构建应用程序了。
这个更改当然是一个临时解决方案,如果您更新location插件,您的更改将被覆盖。但至少在Bintray再次上线(或者您有时间迁移到另一个更近期更新的插件)之前,您将能够构建。 或者 如果问题是由location插件引起的,并且您能够升级到最新版本(目前为4.3.0),那也似乎可以解决问题。在我的情况下,由于一些与Flutter 2不兼容的其他软件包,我被困在旧版Flutter和location上。

2
你好@Magnus。我遇到了类似的问题,但在我的情况下是发生在Firebase库中。例如,我收到的错误与firebase_analytics库有关。但假设我从项目中删除该库,则会出现与cloud_firestore库相关的类似错误(在我的情况下很难删除)--您有什么想法可以帮助我解决这个问题吗?顺便说一句:我正在使用Flutter v2.0.3,旧版本的库(我已经尝试升级但现在太麻烦),以及没有空安全检查的Dart。 - Migalv
我的 location 版本是 4.3.0,但在它的 build.gradle 中也使用了 api 'com.google.android.gms:play-services-location:16.+' - Krahmal

16

看起来是暂时的问题,拥有这些库的服务器已经宕机了。我现在在使用 Room 时也遇到了同样的问题:

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

如果你正在使用Android Studio, 可以尝试使用离线模式,这样它将使用缓存版本的此库(如果您有),直到它被修复为止。

我切换到了一个Flutter库的alpha版本(workmanager),现在它运行得很好。据我所知,它依赖于旧版的Android Room库,由于Bintray不再可用,因此该库已经无法获得。新版本的Room库通过另一个链接下载可用。因此,你的解决方案可能是更新到Flutter位置包的较新版本,或者分支并更改play-services-location的版本为最新版本。


我也遇到了同样的问题,但如果我使用targetSdkVersioncompileSdkVersion 29而不是30,则可以解决。不确定是我的配置有问题还是其他人仍然在使用bintray URL时遇到此问题?status.bintray.com上没有显示任何内容。但它说bintray已被弃用 - 所以是否有任何方法强制构建使用其他URL? - Magnus
1
@Magnus 对我来说,它仍然无法工作,同时更改目标和编译版本也无法修复它... - asmodeoux
@asmodeoux 感谢您的更新。我认为SDK版本29对我有效的原因可能是昨天我构建了它,所以可能被本地缓存了。但今天我不得不升级到SDK版本30,因为Google Play要求升级才能发布更新... - Magnus
嗨,我想问一下,当我以调试模式运行我的项目时没问题,但是当我以发布模式执行 flutter build apk 时和 @AlaeddineBouhajja 遇到了同样的错误。所以我只需要等待更长时间,因为出现了502错误吗? - wahyu
8
我也再次遇到了这个问题……最近服务器似乎非常不稳定,昨天我也遇到了这个错误,但后来它又开始工作了,现在又不工作了。所有这些回答都说用 "mavenCentral() / etc" 替换 jcenter(),但对我来说似乎不起作用,直到错误消息中的URL恢复在线状态,错误才消失。一定有某种方法可以强制gradle使用另一个URL,但是如何操作呢?关闭 WiFi 也不起作用,它会给我另一个与 gradle 相关的错误消息,并立即停止构建。 - Magnus

12

主要问题在于位置3.2.4没有严格的Android依赖版本play-services-location: 16.+

解决此问题的直接方法是在传递依赖项上添加Gradle限制,并在app/build.gradle中指定具体版本。

更新自评论。 您无需修改依赖包或库,而是必须编辑您的项目文件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'
    }
  }
}

6
如果你在location flutter包下遇到了play-services-location问题,可以尝试下一个解决方案:
  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

几点注意事项

  • 如果版本3.2.4适用于您,您可以直接执行步骤4

  • 假设此场景适用于任何其他库。 分支->热修复->更改目标

  • 是的,这并不是一个好的解决方案,但应该允许您在本地或使用任何CI工具继续进行。


你好,"在你的项目中更改获取来自分叉库依赖的方式" 这是什么意思?我如何在我的项目中添加依赖?谢谢。 - Z3R0

4

对于无法找到@Magnus回答中提到的文件夹的人,您可以打开路径下的文件,例如

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

然后更改

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

to

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

2
对于那些遇到问题的人,似乎Bintray服务器最近宕机了。我的临时解决方案是将Gradle构建切换为离线模式,使用缓存来构建应用程序。
进入android->gradlew.bat并修改以下内容,并重新构建您的应用程序:
@rem 执行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

2
这种方法在CI/CD流水线中失败了... - Marcello DeSales
这听起来很有前途,但不幸的是,我也无法通过这种解决方法使其工作。有什么办法可以检查gradle缓存中的内容吗? - Magnus

2
如果您已经有了这些软件包,您可以关闭网络以便在离线模式下使用这些软件包;这是一种解决方案,可以调试您的应用程序,直到服务器恢复正常。

2
经过数小时的调试,我仅仅通过删除旧的 pubspec.lock 文件并将 firebase_messaging^9.1.4 更新到 ^11.1.0 就修复了构建问题。我不知道为什么,也不知道这怎么解决了问题。
看起来是与依赖关系有关的问题。
我通过运行 flutter run --verbose 并分析输出来找到了有问题的依赖关系。

我没有使用任何来自Firebase的依赖。 - Alaeddine Bouhajja
在我的情况下,工作管理器库引起了这个问题,但我已经使用了最新版本,所以这不是我的问题。 - asmodeoux
尝试删除pubspec.lock并运行flutter build,它将生成新的pubspec文件,因为包管理器将获取新的依赖项,这些依赖项可能不依赖于jcenter()。我通过运行flutter run --verbose并分析输出找到了有问题的依赖项。 - Nelu B
Bintray服务器已恢复正常。 - Developer Extraordinare

1
您可以按照以下步骤解决此问题:
  • 修改build.gradle文件如下:
  • 将Kotlin版本更改为1.4.0或更高版本
  • 从repositories中删除jcenter(),并添加mavenCentral()
  • 将构建Gradle工具版本更改为4.1.0或更高版本
 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
}
  • gradle-wrapper.properties文件中的gradle分发版本更改为6.7或更高版本
#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
  • 通过以下命令升级依赖项
flutter upgrade
  • 完成。

1

我有一个简单的解决方案,对我有效。这不是很大的改变,只是一个非常小的改变。增加SDK版本等,请看下面:

    android {
        compileSdk 32
    
        defaultConfig {
            applicationId "com.example.abc"
            minSdk 21
            targetSdk 32
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接