flutter 无法解析此错误,请输入以下网址:

9nvpjoqh  于 2022-12-24  发布在  Flutter
关注(0)|答案(2)|浏览(180)

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

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 *,如下所示,如此处和here所示,但这并没有解决问题

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

项目正常运行,此时发生了该事件。

w8f9ii69

w8f9ii691#

作为切换到另一个位置插件(这可能需要大量的工作和测试)的替代方法,我找到了一个变通方法。下面列出的步骤是针对IntelliJ IDEA的,在其他IDE中可能会略有不同。
1.在“项目”工具窗口(其中列出了您的文件)中,向下滚动直到找到Flutter Plugins。如果您没有看到它,请确保在“项目”工具窗口顶部的下拉列表中选择了Project
1.打开Flutter plugins,找到location-4.0.0并打开它(在location-之后,您可能有不同的版本号,这没关系)。
1.打开文件location-4.0.0/android/build.gradle
1.找到线api 'com.google.android.gms:play-services-location:16.+'
1.将其更改为api 'com.google.android.gms:play-services-location:16.0.0'。如果编辑器显示该文件不属于您的项目,请选择"I want to edit this file anyway"
现在您应该能够构建应用程序了。
这个修改当然是一个丑陋的黑客行为,如果你更新location插件,你的修改将被覆盖,但至少你可以在Bintray重新上线之前(或者直到你有时间迁移到另一个位置插件)进行构建。

hiz5n14c

hiz5n14c2#

在尝试再次模拟应用程序时,在终端上显示错误之前,它向我显示了以下消息:“插件项目:未找到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”包,而是用一个没有location_web依赖项的包来替换它。我使用“geolocator”包来完成这个任务,在我的例子中,我需要它来获取地理坐标,并调用另一个返回地址数据的函数,如下所示:

在公共质量标准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();
    }
  }

相关问题