【问题标题】:Flutter exception Could not resolve com.google.android.gms:play-services-location:16.+颤振异常无法解析 com.google.android.gms:play-services-location:16.+
【发布时间】:2022-01-13 16:54:37
【问题描述】:

伙计们

现在尝试模拟应用程序时,终端抛出异常,应用程序无法启动:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:processDebugResources'.
> Could not resolve all task dependencies 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

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 37s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

Flutter 医生结果:

[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [versão 10.0.19041.1348], locale pt-BR)
 
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Android Studio (version 3.6)
[√] Connected device (1 available)

我已经尝试替换 * project / android / build.gradle * 中的“jcenter” * 传递 * mavenCentral * 如下,如报告herehere,但这并没有解决问题

repositories {
    google()
    mavenCentral()
    maven {
        url "https://maven.google.com"
    }
}

我强调项目运行正常,而这发生在这个时候。

我请求帮助解决。

【问题讨论】:

标签: flutter dart bintray jcenter jfrog


【解决方案1】:

为了再次模拟应用程序,在终端上显示错误之前,它向我显示了以下消息:“未找到插件项目:location_web。请更新 settings.gradle。”和I found that in my project the error was caused by the location package, which has a dependency on location_web

解决方案 也就是说,在他们解决问题之前,解决方案是不使用“位置”包并将其替换为没有此 location_web 依赖项的包。我是使用“geolocator”包完成的,在我的情况下,我需要它来获取地理坐标并调用另一个返回地址数据的函数,如下所示:

在 pubspec.yaml 上:

# location: ^3.0.0
geolocator: '6.2.1'

然后我执行了命令:

flutter pub get

在 AndroidManifest 文件中,我添加了:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

对于我需要的,即获取地理坐标,我使用“geolocator”进行如下操作,替换了之前使用“location”包的代码:

import 'package:geolocator/geolocator.dart';

Future _obtemCoordenadas() async {
    LocationPermission permissao;
    Position _dadosLocalizacao;

    await Geolocator.requestPermission();

    permissao = await Geolocator.checkPermission();
    if (permissao == LocationPermission.denied) {
      permissao = await Geolocator.requestPermission();
      if (permissao == LocationPermission.denied) {
        return;
      }
    }

    if (permissao == LocationPermission.deniedForever) {
      return;
    }

    if (permissao == LocationPermission.always) {
      _dadosLocalizacao = await Geolocator.getCurrentPosition();
      var latitude = _dadosLocalizacao.latitude;
      var longitude = _dadosLocalizacao.longitude;
      localizacao.latitude = latitude.toString();
      localizacao.longitude = longitude.toString();
    }
  }

【讨论】:

    【解决方案2】:

    作为切换到另一个位置插件(可能需要大量工作和测试)的替代方法,我找到了一种解决方法。下面列出的步骤适用于 IntelliJ IDEA,其他 IDE 中的情况可能略有不同。

    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"

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

    此更改当然是一个丑陋的 hack,如果您更新 location 插件,您的更改将被覆盖。但至少在 Bintray 再次上线之前(或者直到您有时间迁移到另一个位置插件)之前,您将能够构建。

    【讨论】:

      猜你喜欢
      • 2022-01-10
      • 2021-06-12
      • 2021-08-17
      • 2022-01-15
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      相关资源
      最近更新 更多