After implementing the GoogleMaps control in my Xamarin.Forms app and distributing my Android app to the Google Play Store, the GoogleMaps map isn’t working. Why??? This has now happened to me for the second time and I thought to do a blog post on this. More as a note to myself, but hopefully this is also helpful to you guys! Fingers crossed I won’t make this mistake for the 3rd time. 😉
We are using this GoogleMaps implementation from amay077 for Xamarin.Forms. There are several community implementations, but we choose this one as it seemed being maintained more frequently and better than others. Though there is always a risk using community projects, as you can’t rely/depend on support from the author. Have to honestly say that we didn’t ran in much issues with this implementation, thanks for the good work amay077, keep it up! 😊
First of all we need to create a Google Maps Api Key for Android and for iOS. You can create these API keys in the Google Developers Console. You need to create a project first and then you can create an API key under APIs & Service -> Credentials -> Create Credentials -> API Key. A full description for Android can be found here and for iOS here. Also don’t forget to enable the Maps SDK for iOS and the Maps SDK for Android (I did this and it took me some time to figure out why my API key wasn’t working for my GoogleMaps implementation)! You can click on Library in the left menu, search for Maps SDK and click on both the Android and iOS version and Enable both.
Next you’ll need to restrict the API key to prevent unauthorized usages in production. You can restrict each API key to be used for a particular application (f.e. Android, iOS and some more). When you choose iOS you only have to add your app’s Bundle ID from your iOS application. For Android you also have to add your app’s package name from your Android application, but you’ll also have to add a SHA-1 certificate fingerprint.
Each Android application (APK package) is generated with a keystore file. Even if you are debugging, Visual Studio uses a debug.keystore file which is unique for each development environment. For a Store distribution you’ll need to generate a keystore file once and for each distribution sign your Android application (APK package) with this keystore file to be able to update your application in the Google Play Store. For each keystore that your app is possibly signed with, you’ll need to generate a SHA-1 certificate fingerprint. So for every developer that is developing together with you on your application, you’ll need to generate this SHA-1 certificate fingerprint and register it on you Google API key. When you select Android application restriction, the Google Developer console shows you exactly how to do this.
Now we are all set to use our created API key(s) in our application(s). When we initialize the GoogleMaps implementation with our created API key, we can now use the Google Maps map in our Xamarin.Forms app!
We’ve generated a SHA-1 certificate fingerprint for the debug keystore and also the keystore file we use for signing our Android application for the Google Play Store. We’ve tested the GoogleMaps map in debug mode and also created an Ad-Hoc APK package with our production keystore file and verified that’s also working. Now we are ready to distribute our Android application to the Google Play Store! Everyone is happy and excited to download and install the Android application from the Google Play Store, but then suddenly the GoogleMaps map isn’t working! Even after thoroughly testing our Android application. I’m not sure when Google decided to do this, but apparently there is a difference between the upload certificate (that is generated from the keystore file that we generated for our Android application) and the actual app signing certificate. And that SHA-1 certificate fingerprint isn’t configured on our Google API key.
Luckily we don’t have to distribute a new package to solve this problem. We can easily fix this by getting the SHA-1 certificate fingerprint that the Google Play Store created and configure this on our Google API key. To get this SHA-1 certificate fingerprint, login to the Google Play Console go to your Android application -> Release Management -> App signing. Then you’ll see the SHA-1 certificate fingerprint underneath app signing certificate. Configure this on you Google API key, wait for a few minutes for the settings change to take effect, start your Android application and voilà! Your GoogleMaps map is working again! 😊