0

I'm trying to set up google maps in flutter following this tutorial, but I'm running into some issues. My app runs but I'm seeing a white screen without anything happening and the following error is printed to the terminal:

E/MethodChannel#flutter/platform_views(13225): Failed to handle method call
E/MethodChannel#flutter/platform_views(13225): java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml

Which is weird, because my AndroidManifest.xml looks like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.studievriend">
    <!-- Flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application>
        <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIxxxxxxxxxxx-xxxxxxxxxxxxxxx_xxxxxx"/>
    </application>
</manifest>

It's exactly what the error is asking for so I don't know what's wrong. I've looked at other threads and done some suggested things like running removing the application, flutter clean and retry flutter run, which is also not working.

These are my dependencies inside of pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  location: ^4.1.1
  cloud_firestore: ^1.0.5
  firebase_core: ^1.0.3
  google_maps_flutter: ^2.0.3

I would like to add geoflutterfire: ^2.0.2 aswell, but then I'm getting the following error

Because geoflutterfire >=2.2.2 <3.0.0-nullsafety.1 depends on cloud_firestore ^0.16.0 and studievriend depends on cloud_firestore ^1.0.5, geoflutterfire >=2.2.2 <3.0.0-nullsafety.1 is forbidden.

So, because studievriend depends on geoflutterfire ^2.2.2, version solving failed.

I've tried some other versions aswell but I keep getting errors.

I would really appreciate it if someone can help me with this!

Jip Harthoorn
  • 292
  • 1
  • 8
  • 25
  • Looks similar to this [issue](https://github.com/flutter/flutter/issues/28719) and it was resolved by following this [guide](https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects) – Nelson Jr. Apr 16 '21 at 01:35
  • @NelsonJr. I created the project today so I don't think this applies to me – Jip Harthoorn Apr 16 '21 at 16:21

1 Answers1

2

You used the wrong AndroidManifest.xml. Please use the AndroidManifest.xml in the app directory, not in the debug directory. The debug Manifest is only used for flutter itself. The right one should be in this location:

android\app\src\main\AndroidManifest.xml

For your other error, you might need to import a lower version of geoflutterfire, because there is a version conflict. You imported cloud_firestore: ^1.0.5 but the geofluttefire depends on a newer version.

Lars
  • 1,250
  • 9
  • 25
  • Thanks that's correct, I didn't see there was another AndroidManifest. The error is now gone, but the app is really really slow, after a 2 minute black screen I'm seeing half a strechted unresponsive map. This is the output in the terminal https://pastebin.com/nUwcrj9Z. Any idea what's wrong? Also, 1.0.5 is the newest version of cloud_firestore (https://pub.dev/packages/cloud_firestore), so how does geoflutterfire depend on a newer one? – Jip Harthoorn Apr 16 '21 at 09:51
  • @JipHarthoorn you are right, I mistyped :/ it should say an older version of firestore. Please try importing the newest version of geoflutterfire, which is the 3.0.0 nullsafety one. Can you provide the code you use for displaying the map and which device you are testing on? – Lars Apr 16 '21 at 09:53
  • @Irsvmb the nullsafety one works! My main.dart looks like this: https://pastebin.com/j2N1F3E0. It's the same code as they use in this tutorial: https://fireship.io/lessons/flutter-realtime-geolocation-firebase/ – Jip Harthoorn Apr 16 '21 at 10:06
  • @JipHarthoorn What device are you testing it on? Are there any other services in your app running? – Lars Apr 16 '21 at 11:32
  • @Irsvmb sorry forgot to mention it, I'm running the app on a Samsung Galaxy S8, I don't think I have any other services running, not sure what you mean tho. – Jip Harthoorn Apr 16 '21 at 13:27
  • It finally works and runs smooth! I ran `flutter doctor` and saw that I had to run `flutter doctor --android-licenses`. This gave me an error, but after trying a lot of things, this solution fixed that: https://stackoverflow.com/a/64163047/10054433. After that everything works fine. – Jip Harthoorn Apr 16 '21 at 21:30