Thursday, July 19, 2012

How to use keytool in java to generate key store to use MapView in Android?

Android MapView needs a MD5 key to access Google Maps on Android device or emulator. To do that we need to generate key store using java toolkit's keytool.exe.

Following command shows how to generate key store using keytool:
Command: C:\Program Files\Java\jdk1.6.0_30\bin>keytool -genkey -alias android -keyalg RSA -keystore <keystre.jks-path> -keysize 2048 -keypass <password>

For above command you can you JDK 1.6 or JDK 1.7. I tried the command with both versions.

How to find the MD5 key store if you have already generated it in past?
Command: keytool -list -v -keystore <keystore path>

Above command will ask you for that password. Provide the password you used to generate the key store. If you are using JDK 1.7 then don't forget to mention "-v" in above command otherwise you will get "SHA1" key only as output.

Issues faced:
1. I noticed in few post people mentioned that use keytool.exe from JDK 1.6, using JDK 1.7 key tool generates key store in SHA1 format instead of MD5 format which is required for MapView. That is not the case. Above command (keytool -list -v -keystore <keystore path>) will give you output of all the key in all available formats.

2. While generating key store you might get error -> keytool error: keystore.jks (Access is denied)
This can happen because you don't have write permission in the directory where you are planning to generate key store.

3. You might also get Google map signed api key errors in Android which will look like follows: Server returned: 3
This can happen if you have forgotten to generate debug keystore in MD5 format. Following command might just do the trick for you:

C:\Program Files\Java\jdk1.6.0_30\bin>keytool -list -alias <androiddebugkey> -keystore <debug.keystore path> -storepass android -keypass <password>

androiddebugkey, Jul 17, 2012, PrivateKeyEntry,
Certificate fingerprint (MD5): 12:16:C2:...
Copy above output printed after key "(MD5):" text and use it to obtain your apiKey from link:

For more information look at link:

Note: Debug key only works in debug mode. Debug key will not work in production mode. When you upload your app on Android Market Place, you will have to generate key again. Look at LINK for more information.

  1. Android MapView tutorial:
  2. The Most Common Java Keytool Keystore Commands:

No comments:

Post a Comment

Example code to connect node.js REST service with Eureka discovery service

Eureka is Spring based discovery service developed by Netflix. To know how Eureka is used at Netflix visit: