Massau
Massau

Reputation: 49

Flutter exception Could not resolve com.google.android.gms:play-services-location:16.+

In trying to emulate the application now, the terminal throws an exception and the application won't start:

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 doctor result:

[√] 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)

I've already tried replacing "jcenter" in * project / android / build.gradle * passing * mavenCentral * in place as follows, as reported here and here, but that didn't fix the problem

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

The project was working normally and this occurred at this time.

Upvotes: 2

Views: 2798

Answers (2)

Magnus
Magnus

Reputation: 18790

As an alternative to switching to another location plugin (which might require a lot of work and testing), I found a workaround. The steps listed below are for IntelliJ IDEA, things probably look slightly different in other IDE's.

  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 an ugly hack, 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 location plugin).

Upvotes: 1

Massau
Massau

Reputation: 49

In an attempt to emulate the application one more time, before displaying the error on the terminal it showed me the following message: "Plugin project :location_web not found. Please update settings.gradle." and I found that in my project the error was caused by the location package, which has a dependency on location_web

Solution That said, until they fix the problem, the solution is not to use the "location" package and replace it with one that doesn't have this location_web dependency. I did it using the "geolocator" package and in my case I needed it to get the geographic coordinates and call another function that returned the address data, looking like this:

On pubspec.yaml:

# location: ^3.0.0
geolocator: '6.2.1'

And I executed command:

flutter pub get

In AndroidManifest files, I added:

<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"/>

For what I needed, which was to get the geographic coordinates, I did it as follows using "geolocator", replacing the previous code that used the "location" package:

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();
    }
  }

Upvotes: 0

Related Questions