Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Android Google Map v2 working in release version by generating SHA1 fingerprint for API key

I spent a long time tonight trying to figure out how to get my Google Map that worked in the debug version of my Android application to work in the release version. There were a few different problems that came up. Some fragments of Stack Overflow posts helped, but I thought it would be useful to list more detail for the whole process, including the problems I had, which were:

1) How/where do you specify something different for your release version?

2) How do you run the keytool executable needed to get the release version fingerprint?

3) Why was I getting the "keystore file exists but is empty" error when running keytool?

like image 990
Eric Barr Avatar asked Dec 08 '14 04:12

Eric Barr


People also ask

How do I ensure Google Maps Android API v2 is enabled?

Click on “Create Project”. Enter the project name and id of your choice. Click on the “APIs & auth” menu on the left, and from the submenu select APIs. From the list of APIs that appear, scroll down and ensure that Google Maps Android API v2 is set to “On”.

How do I get my Google map API key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key. Click Close.

How do I get SHA-1 fingerprints?

Open a terminal and run the keytool utility provided with Java to get the SHA-1 fingerprint of the certificate. You should get both the release and debug certificate fingerprints. Note: When using Play App Signing, the upload key certificate will be different than the app signing key certificate.


2 Answers

1) As specified in a couple other Stack Overflow posts, you can use the same Google API key for both your debug and release versions, but you have to supply the fingerprints of your debug and release keys in the Google Developers Console.

  • Log into Google Developers Console https://console.developers.google.com
  • Choose your appropriate Project
  • On left side, choose Credentials under "APIs & auth"
  • Assuming you already have an API Key generated for Android applications, you should already see your application listed as an "allowed application" with its debug fingerprint. Click "Edit allowed Android applications".
  • You will want to add another line for your application, but with its release fingerprint. To get that...

2) Google mentions in that dialog that you need to run

keytool -list -v -keystore mystore.keystore

But by clicking "Learn more" and going a little further, what you really want to run is

keytool -exportcert -alias MY_RELEASE_KEY_ALIAS -keystore MY_FULL_PATH_TO_RELEASE_KEYSTORE_FILE -list -v

Then you'll be asked for your keystore password. One piece that isn't mentioned in the docs is where the keytool program is. Its in your JDK bin folder. So on Windows, something like C:\Program Files\Java\jdk1.8.0_20\bin

3) After I opened a console window in the Java bin folder and ran the keytool as above, I was getting an error that said "keystore file exists but is empty". Eventually I realized that when specifying the full path to my release keystore file, I had only specified the folder name but forgot to include the actual file name, even though there was only one file in the folder. So MY_FULL_PATH_TO_RELEASE_KEYSTORE_FILE above should include the .keystore file name

After all that, you will be finally be provided with several fingerprints, including the SHA1. You can copy that, and go back and paste it as a new line in the allowed Android Applications, with your package name on the end separated by a semi-colon, just like the debug one.

like image 175
Eric Barr Avatar answered Oct 23 '22 13:10

Eric Barr


Follow the instructions given here. After creating your project in Google Developers Console, select APIs, you will be prompted with a section of Popular APIs, select Google Maps Android API. Press enable API.(the image below is showing the steps in the new version of the console) console's new version

If you're still using the old console, enable the API, by selecting Services, then switch the button ON:

enter image description hereNote: You don't need to enable the API for the debug version!

If you're map is still not showing try regenerating the key!

(new version) enter image description here

(old version)

enter image description here Enter the new API key then Sync Project with Gradle Files!

like image 38
kinsell Avatar answered Oct 23 '22 15:10

kinsell