- Microsoft Windows 7 Pro
- Android Studio v0.8.6 beta
- Java Development Kit v1.8.0_20
What?
The article below serves as a checklist to ensure I don't release an app that only displays maps to myself (again).
Why?
This took me a while to figure out so hopefully this will help others.
How?
The gist is that I was using the Test SHA1 when adding allowed Android Keys to the Google APIs console (there's so many) when I should be using the App SHA1 (I have now added both to the console).
- [Optional] To use the keytool: If you know the command prompt, you know that you have to refer to each tool using their full path unless you add it to the PATH environment variable:
- This allows you to use keytool from any folder:
- Open a command prompt
- Type CD C:\Program Files\Java
- Determine your JDK folder dir jdk* and append the \bin. Note this for later.
- Right-click on the "Computer" icon/label (desktop / start menu)
- Select Properties
- Click on Change settings or Advanced system settings
- Select the Advanced tab
- Click on the Environment Variables... button
- Under "System variables" find the PATH variable and add the JDK bin folder you noted earlier:
- Click on OK and close the respective dialogs (note that setting the variable via the command prompt will NOT work!)
- To get the Test SHA1 code: Creating a Google Maps project in Android Studio (v0.8.6 beta) "creates" a SHA1 along with the project name: something similar to: 5B:3D:C4:92:CA:D5:12:89:45:1D:E2:64:CF:C8:21:F8:04:38:F2:3E;com.example.myapp. By default this is the SHA1 of your computer but add it anyway to the Google APIs console for testing purposes. To get it again:
- Finding your computer's Certificate Fingerprint SHA1
- Open a command prompt
- Type CD C:\Program Files\Java
- Determine your JDK folder dir jdk*
- Change directory to the JDK folder cd jdk<press tab key here>
- Change to bin folder cd bin
- Type (replace <your_username> with your windows login)
- To get the App SHA1 code: You have to add the correct SHA1 to the Google APIs console for release purposes. This is the SHA1 from the certificate (*.jks) you used to upload the APK to the Google Play Developer Console.
- Finding the Certificate Fingerprint SHA1 of an existing keystore
- Open a command prompt
- Type CD C:\Program Files\Java
- Determine your JDK folder dir jdk*
- Change directory to the JDK folder cd jdk<press tab key here>
- Change to bin folder cd bin
- Note the name of the JKS file you use to sign an uploaded app
- Type (replace <your_username> with your windows login and <your_jks_file.jks> with the JKS file you used)
- Enter the password for the key store and you should get something like the following (don't use this one but it will look like this):
- This tells me the alias is "myexampleapp" for this keystore and the SHA1 to add to google which would be:
* In the above, if you have specified the correct bin folder in your PATH environment variable, then you can use the keytool from any folder, skipping the initial steps of navigating to the JDK folder.
- Changing a keystore password
copyraw(replace <new_password> with your windows login and <my_keystore.jks> with your JKS file)
keytool -storepasswd -new <new_password> -keystore <my_keystore.jks>
- keytool -storepasswd -new <new_password> -keystore <my_keystore.jks>
- Changing a key password
copyraw(replace <new_password> with your windows login, <my_keystore.jks> with your JKS file) and <my_alias> with the app alias.
keytool -keypasswd -alias <my_alias> -new <new_password> -keystore <my_keystore.jks>
- keytool -keypasswd -alias <my_alias> -new <new_password> -keystore <my_keystore.jks>
The above solved it for me
I had registered my computer SHA1 with the Google API console instead of the app SHA1, but here are some red herrings I found when debugging this issue:
- Download from the Play Store:
The google maps api will apparently NOT work if you downloaded the APK from another location. This wasn't the issue, once I had the right SHA1 registered in the Google APIs console other users could download the file from my website and see the maps. I'm not saying it won't fix a problem for you, just that downloading from the Play store was unrelated to the above.
Additional:
If you forget your key (like I did) and which keystore file you used, then you'll have probably tried this:
- Upload the APK to the Google Play store using a different key
- The Play store will tell you there's a mismatch on the SHA1 fingerprints used and will display both of them to you.
- Using the keytool you can reverse engineer this and work out which certificates were used for which APK listed in the store.