Search code examples
androidgoogle-mapsgoogle-maps-android-api-2

How to add multiple Google Maps API configs in a multi-flavor app


I have a multi-flavor Android app because I need my dev, qa and prod applications with different IDs to connect to different Firebase projects.

flavorDimensions "env"
productFlavors {
    dev {
        dimension "env"
        applicationId "com.myapp.debug"
    }
    qa {
        dimension "env"
        applicationId "com.myapp.beta"
    }
    prod {
        dimension "env"
        applicationId "com.myapp"
    }
}

I also added 3 versions of google_maps_api.xml in the respective source folders like so:

enter image description here

In the dev version, everything works smoothly, the maps shows OK. But when I release the app in closed alpha after generating a signed version with the release/qa variant, the map doesn't show in the app.

Since I'm still a newbie in Android, I don't know what I might have missed or even how I can troubleshoot this issue? Is there an easy way to see the logs of the qa version released in closed alpha? Am I missing something obvious? Where should I find the google_maps_api.xml file in the signed APK, so that I can check that the right one is in there?


Solution

  • I think I figured out what I missed. I opted in to Google Play App signing, so I'm signing my app with an upload key, and then Google signs it with a deploy key that it keeps. And I found this piece of documentation, that says I have to get my SHA-1 fingerprint from Google and use this in my Google Maps API key. So I exported that SHA-1 and I pasted it into my Google Maps API key configuration and now it seems to work fine.