My google map app works fine on device with debug google map API KEY but when I create signed apk for my app with release google map API KEY, it does not display map. To gen
I had a similar issue and the problem was that I generated the apk from Android Studio without first selecting the right flavour. This means my manifest was still using the Google Maps API key that I created for the debug flavour.
Please make sure you select the release flavour in your Android Studio. See screenshot below:
you cannot use same key that you used in debug in the release, they have different works. to solve this problem you have to generate new Google map key API KEY form the key store that you are using in you release copy see this video for more details https://www.youtube.com/watch?v=xLJ0jDFdUZ0
In the Google Api console, where we have created the API KEY we have an option to add multiple finger prints to the same key. What I did was adding two SHA1 finger print for my debug keystore and release keystore and the same API key worked for me.
Note the below is for Ubuntu specifically:
Get SHA1 for the debug using the below command
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
For getting SHA1 for release the command changes to
keytool -list -v -keystore /home/atul/Desktop/Learnings/Projects/TestApp/keystore.jks -alias test -storepass password -keypass password
where
/home/atul/Desktop/Learnings/Projects/TestApp/keystore.jks
is the path where my keystore file for the signed apk is present
test
is the key alias name used while genrating the signed key store
and password
is the password used while signing the apk
Hope this helps. Happy coding :)
I had a similar problem: after creating a couple of new variants builds with same type ("release") but some new flavors ("free" and "premium"), the Google Maps fragment did not show anymore the maps and the screen appeared totally blank. In the logcat I could only see next error message "Unexpected response code 400 for https://clients4.google.com/glm/mmap/api" that probably was indicating some problem with the Google Maps API access.
Of course I reviewed again all the Google Cloud API process in order to check if something was missing in my API key credentials, but I did not find anything wrong. In fact, for new APK's it is indicated to add the builds info (name+fingerprint) to the existing Project Credentials in order to inherit the same API key that is still valid.
The instructions that we can read are very clear: "Add your package name and SHA-1 signing-certificate fingerprint to restrict usage to your Android apps. Get the package name from your AndroidManifest.xml file. Then use the following command to get the fingerprint: keytool -list -v -keystore mystore.keystore".
The problem in my case was that my new variants "package names" were not the one existing in the Manifest package name ("com.example.app_name.release"). In fact, due to my new flavors I had the same Manifest name BUT two new "real" package names: "com.example.app_name.free.release" and "com.example.app_name.premium.release". Those names do not appear written in the Manifest file as such as they correspond to the Gradle configuration where flavors are defined (in my case with "applicationIdSuffix" attribute). This is quite confusing for me as Gradle "application id" should not overlap the Manifest "package name". But when we read carefully all the Android documentation, we can read "if manifest package name is different than Gradle applicationId, build will copy the application ID in final manifest file". Of course, both variants have the same fingerprint as both are still of the same build type ("release").
So the solution was to add in the same Project Credentials the two new variant entries to inherit the same API key:
original entry (don't need to delete it): Package name = "com.example.app_name.release" - SHA-1 certificate fingerprint = "xxxxx"
new entry 1: Package name = "com.example.app_name.free.release" - SHA-1 certificate fingerprint = "xxxxx" no change, same as used until now
new entry 2: Package name = "com.example.app_name.premium.release" - SHA-1 certificate fingerprint = "xxxxx" no change, same as used until now
Finally, it may be needed to clean your build in order to ensure that you are really watching the correct updated behavior in your maps fragment or activity.
About the rest of recommendations, in my case I did not have to apply them: - no need to hardcode the API key in the Manifest - no need to create a new API key for the new variants APK's - no need to use the google_maps_api.xml files
Google key has two types of Security.
1.Non restricted key
2.Restricted key (Android restricted through SHA-1)
Note: Use Restricted key for Maps,Places, but not for Google Directions. use Non restricted api key for google Directions . bcz its web based api response so restricted key doesnt work.
-> When using Non Restricted key
-> When usingRestricted (Android SHA-1) key
Step - 1 : look into two google_maps_api.xml files, one in the app/src/debug/res/values folder and the other in the app/src/release/res/values folder, but only the debug one contains your API key. make sure key is same in both files.
Step - 2 : Generate SHA-1 using AndroidStudio (gradle tab in Left Pane and select signing Report) and add as a item in google Developer console for the Api key which your using.
Step - 3: As soon as you generated Signed Apk google will overwrite your Androidstudio generated SHA-1 a with google own SHA-1 key. so u need to get tht also to be added for Api key in Api key in Developer console
Goto Release Management -> App Signing -> and copy the SHA-1 certificate fingerprint from App signing certificate
Paste this newly copied SHA-1 fingerprint to Developer Console and map in release mode will show.
Step 4: Add Release build SHA-1 also to Api key in Developer console like below.
Goto Release Management -> App Signing -> and copy the SHA-1 certificate fingerprint from Upload certificate
Paste this newly copied SHA-1 fingerprint to Developer Console and map in release mode will show.
I had this Problem and running these steps I think this way is perfect and complete
For Android Studio: