无法获取“play-services-location/maven-metadata.xml”。从服务器收到状态代码 502:网关错误

Ala*_*jja 52 android artifactory gradle bintray flutter

我有一个项目,昨天运行得很好,但是今天我发现这个问题:

无法解析配置“:app:debugRuntimeClasspath”的所有文件。无法解析 com.google.android.gms:play-services-location:16.+。必需者:项目:app > 项目:位置 > 无法列出 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”。> 无法获取“https://google.bintray.com/exoplayer/com/google/android/gms/play-services-location/maven-metadata.xml”。从服务器收到状态代码 502:网关错误

实际上我正在使用classpath 'com.android.tools.build:gradle:4.1.0'with 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但仍然出现错误。

安卓/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
}
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

另外,我已将compileSdkVersionminSdkVersiontargetSdkVersion更改为30,但什么也没发生。

Mag*_*s W 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'. 如果您的编辑器说该文件不属于您的项目,请选择"I want to edit this file anyway"

您现在应该能够构建该应用程序。

此更改当然是临时解决方案,如果您更新location插件,您的更改将被覆盖。但至少您将能够构建直到 Bintray 再次上线(或者直到您有时间迁移到另一个最近更新的插件)。

或者

如果问题是由位置插件引起的,并且您能够更新到它的最新版本(4.3.0目前),这似乎也可以解决问题。就我而言,我被困在旧版本的 Flutter 上,并且location因为其他一些软件包与 Flutter 2 不兼容。

  • 你好@Magnus。我遇到了类似的问题,但就我而言,它发生在 Firebase 库中。-- 例如,我收到的错误与 firebase_analytics 库相关。但是,假设我从项目中删除了该库,然后 cloud_firestore 库出现了类似的错误(在我的情况下,删除该库要困难得多)——您知道我可以做些什么来解决这个问题吗?-- 顺便说一句:我正在使用 Flutter v2.0.3、旧版本的库(我已经尝试升级,但现在工作量太大)和 Dart,没有声音空安全 (2认同)

asm*_*oux 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
Run Code Online (Sandbox Code Playgroud)

如果您使用的是 Android Studio,您可以尝试使用离线模式,然后它将使用该库的缓存版本(如果您拥有该库)直到修复为止。

我切换到了 flutter lib 的 alpha 版本,这导致了这个问题(workmanager),现在它运行良好。据我了解,它依赖于旧版本的 Android Room 库,由于 Bintray 不可用,该库不再可用。新版本的 Room 可以通过另一个链接下载。因此,对于您来说,解决方案可能是更新到较新版本的 Flutter location 包,或者分叉它并将 play-services-location 的版本更改为最新版本。

  • 我也再次遇到这个问题......最近服务器似乎很不稳定,我昨天也遇到了错误,但后来它开始工作,现在又无法工作了。所有这些答案都说 _replace jcenter() with mavenCentral()/etc_ 似乎对我不起作用,错误持续存在,直到错误消息中的 URL 返回在线状态。必须有某种方法强制 gradle 以某种方式使用另一个 URL,但是如何呢?关闭 wifi 也不起作用,它给了我另一个与 gradle 相关的错误消息并立即停止构建。 (8认同)

Ser*_*kov 12

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

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

从评论更新。你不需要修改依赖包或lib,你必须编辑你的项目文件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'
    }
  }
}
Run Code Online (Sandbox Code Playgroud)


Eld*_*tov 6

play-services-location如果您在 flutter 包下遇到此问题,location您可以继续执行下一个解决方案:

  1. 对存储库flutterlocation进行分叉

  2. 在分叉项目中进行更改。(您可以在此提交中检查所有更改)

  3. 承诺吧。推它

  4. 在您的项目中更改从分叉库获取依赖项的方式

    location:
      git:
        url: git://github.com/dreambitio/flutterlocation.git
        ref: release/3.2.4
      path: location/
    
    Run Code Online (Sandbox Code Playgroud)
  5. 完毕

一些笔记

  • 如果版本 3.2.4 适合您,您可以选择step 4

  • 假设此场景适用于任何其他库。Fork->Hotfix->Change target

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