Google Maps not working in release build even with correct SHA1 key in Flutter

Viewed 2246

I am using google_maps_flutter 1.0.6 plugin to display maps in my flutter app. The map is shown perfectly in debug version but it does not show in release build. I have entered the SHA1 key for the release build in the restrictions and have checked it multiple times and it is correct. I have also tried triggering the onMapsCreated method. It is triggered in debug build but it it does not run in the release build. Can someone explain what can I do to make Google maps work in the release build.

Here is the info about Flutter version I am using:

Flutter 1.22.3 • channel stable • https://github.com/flutter/flutter.git

Framework • revision 8874f21e79 (3 weeks ago) • 2020-10-29 14:14:35 -0700

Engine • revision a1440ca392

Tools • Dart 2.10.3

2 Answers

The issue was with the widgets and not the Maps API and SHA1 key. I wrapped GoogleMap widget with Container and then wrapped the container with an Expanded widget. This widget tree was working perfectly in the debug build and was displaying the Map on the screen but in the release build somehow it did not show the map.

I just removed the Container and Expanded widget wrapping the GoogleMap widget. And it surprisingly worked in the release build.

In my case, it was related to SHA1.

I followed this tutorial to do the release generating the keystore.

https://medium.com/@psyanite/how-to-sign-and-release-your-flutter-app-ed5e9531c2ac

Once I had the .jks or .keystore file generated in my computer.

I got the SHA1 running keytool -v -list -keystore nutella.jks

And added the SHA1 to the Android key in https://console.cloud.google.com/google/maps-apis/credentials

I then run flutter build apk --release and Google Maps worked fine in this new APK.


Additionally, if it helps anyone. These are some of the config in my project:

dependencies:
  google_maps_flutter: ^1.1.1
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath 'com.google.gms:google-services:4.3.10'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
android {
    compileSdkVersion 30
}

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 30
        multiDexEnabled true
    }

    buildTypes {
        release {
            signingConfig signingConfigs.release
            shrinkResources false
            minifyEnabled false
        }
    }
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Related