Although there are more irritating things to have to wade through (a good example being nuget package dependency untangling, we’ve all been there. And if you haven’t yet, good for you), figuring out how to use the Java keytool is high on the list.
I found I needed it to get started using Google APIs for Xamarin.Form.Maps. Although the guide provided by Xamarin looks simple enough….
“Obtaining a Maps API v2 key involves the following steps:
- Retrieve the SHA1 fingerprint of the keystore that is used to sign the application.
- Create a project in the Google APIs console.
- Obtaining the API key.”
…do not be fooled, wary traveler. Retrieving the elusive SHA1 fingerprint is not as simple as you think. You fool, you.
And this is where the Keytool comes in. The Xamarin guide will explain that you need to use this tool to get your fingerprint from a keystore.
“By default the keystore that is used to sign debug versions of a Xamarin.Android application can be found at the following location:
- Windows –
C:\Users\[USERNAME]\AppData\Local\Xamarin\Mono for Android\debug.keystore
- OSX –
/Users/[USERNAME]/.local/share/Xamarin/Mono for Android/debug.keystore
Information about a keystore is obtained by running the
keytool command from the JDK. This tool is typically found in the Java bin directory:
- OSX –
- Windows –
C:\Program Files (x86)\Java\jdk[VERSION]\bin\keytool.exe“
Both of which are easy enough.
And you too! Don’t think you can hide from me!
And here is where morale begins to ebb away. It closes down the moment you open it. Hmm.
It actually is working. Its just that you send it commands, and they run immediately, shutting down once done. That is why you’ll need to use the command prompt for it to stay open and you to see what the dang is going on. And the suggested route of:”
keytool -list -v -keystore /Users/[USERNAME]/.local/share/Xamarin/Mono\ for\ Android/debug.keystore -alias androiddebugkey -storepass android -keypass android” does not work as easy as one would think.
Rather, the following steps will get it for you:
- Start Menu/Search Programs/Command Prompt
- Type and enter “cd C:\Program Files (x86)\Java\jre1.8.0_91\bin” (or the location of your computers Java keytool, if its a different version, which doesn’t matter at all)
- keytool -list -v -keystore “%USERPROFILE%\AppData\Local\Xamarin\Mono for Android/debug.keystore” -alias androiddebugkey -storepass android -keypass android
- Yay! I see it!
- Right click and select all, and then CTRL-C. Paste it all in a notepad, and you have you fingerprint!
I have you now Skywalker….
It took me an hour and a half to figure this out. Now, I may be stoopid, but judging by how many stackoverflow SOS messages there seem to be on this topic, it is not so simple a quest.
Hopefully this makes it easier.
Now I’m off to go get my maps!