21

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 generate release mode google API KEY , i am using SHA1 fingerprint with my keystore. And i am also defining "signing and build types" in my project Settings as explained by developer.android.com(http://developer.android.com/tools/publishing/app-signing.html).

Tried every possible solution(removing apk and than reinstalling it again, restarting the device, cleaning the project ). nothing worked. Anybody have a good solution to my problem please help. FYI Using android studios platform.

sam2395
  • 229
  • 1
  • 2
  • 7
  • can create map api key by using keyStore of SHA1 – Naveen Tamrakar Nov 06 '14 at 11:50
  • Can you attach a screenshot of your API console with api keys? – romtsn Nov 06 '14 at 11:51
  • You can use the same Google API key both to debug and release fingerprints. – romtsn Nov 06 '14 at 12:28
  • 8
    i had this same problem,my case it added the apikey to debug>res>values>google_maps_api.xml but forgot yo add release>res>values>google_maps_api.xml .now it works fine – Shabeer Ali Jun 25 '15 at 06:01
  • THANK YOU FOR PUTTING THE FILE PATHS --- which made very clear the situation ---- i would kiss you right now if were to stand in front of me. i spent so much time to find this bloody answer. – DoruChidean Nov 23 '15 at 12:32
  • Thank you so much Shabeer, i just spent hour and hours trying to figure this out. Thanks!! – Enpi Jul 25 '16 at 10:15
  • Kindly have a link on my given answer on this link http://stackoverflow.com/questions/16978270/after-exporting-apk-the-google-maps-do-not-show-in-application-why-does-it-happ/42220296#42220296 – Dharmbir Singh Feb 14 '17 at 07:37
  • **Kindly have a look on this video to create SHA1 for release** https://youtu.be/g75cZXjmuj8 – Dharmbir Singh Feb 14 '17 at 10:53

16 Answers16

29

Maybe you have 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.

Arslan Anwar
  • 18,746
  • 19
  • 76
  • 105
15

The API key needs to be hardcoded into the Android Manifest, and it doesn't work if it's in a separate resources XML file.

Chrismas007
  • 6,085
  • 4
  • 24
  • 47
Florence Herrou
  • 175
  • 1
  • 4
  • 2
    This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](http://stackoverflow.com/questions/ask). You can also [add a bounty](http://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question once you have enough [reputation](http://stackoverflow.com/help/whats-reputation). – Chrismas007 Jan 19 '15 at 14:36
  • 4
    Maybe my poor english is the problem. I had the same issue, and I resolved it by moving the API key from a separate resource XML file to the Android Manifest. I don't know why it did work on debug and not with a signed APK, but since the only change I made was moving the API key, it was the solution for me. – Florence Herrou Jan 19 '15 at 14:50
  • 1
    Man, you really saved my mental sanity. I was struggling with this problem for a couple of days, and never thought about this: android studio creates a separate resource file for the key when using the map wizard, i assumed it was correct. Thanks a million! – Manzotin Apr 17 '15 at 09:37
  • I have a same problem and my key is also in manifest, but ap show blanks when I generate singed apk. – Mahdi Nov 14 '15 at 04:50
  • this really saved my day! should be selected as verified answer! – Rez May 02 '16 at 08:49
  • I don't know why google wizard generate separate file if it is not work in release apk ?!!!! . but your answer worked for me.thank you ;) – MHP Aug 21 '16 at 00:22
  • This answer is wrong. While it does work to put an API key hardcoded in the manifest, it is not necessary. It will work just fine in a separate xml resource if configured properly. See here for more info: https://stackoverflow.com/questions/30559602/android-studio-google-map-still-blank-on-real-android-device-on-release-build – Daniel Nugent Sep 20 '17 at 22:48
6

Debug certificate is different from your production certificate. You need to add both to your Google Maps key entry in your API console as seaparate row - each with the same packageId, but naturally different SHA1 hash.

EDIT

There's no limit of how many certificate fingerprints and package names are assigned to single Google Maps key, so unless you need this separated is's perfectly fine to have both development and production builds using the same key. In google console it would be like this (one sha1 is from debug cert, which is the same for all apps you build using this IDE, other is production cert):

83:10:58:52:EF:3B:59:70:2B:28:9E:AE:4F:5E:1D:F0:7E:19:FB:F1;com.foo.bar
AE:4F:5E:1D:F0:7E:19:FB:83:10:58:52:EF:3B:59:70:2B:28:9E:AA;com.foo.bar

or even (but I do not recommend using same key for different apps):

83:10:58:52:EF:3B:59:70:2B:28:9E:AE:4F:5E:1D:F0:7E:19:FB:F1;com.foobar.myapp
AE:4F:5E:1D:F0:7E:19:FB:83:10:58:52:EF:3B:59:70:2B:28:9E:AA;com.foo.bar
EF:3B:59:7E:19:FB:83:10:58:57:AE:4F:5E:1D:F0:2B:28:DE:9E:01;net.something.otherapp
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Of Course for release mode we need different SHA1.I was generating two separate google map keys before. Tried your way of keeping both the certificate in same Map Key but no luck. Tried everything as explained(https://developers.google.com/maps/documentation/android/start#displaying_certificate_information) here. App with debugging certificate works fine, but when shifts to release mode it does not show map. Am I missing something in android studios while generating the APK file. Thanks. – sam2395 Nov 07 '14 at 04:57
  • @marcin-orlowski is correct. As long as you added your release key fingerprint to the "Allowed Android applications", with the package name on the end separated by a semi-colon, then your release APK should show the map too. I wrote a post with some more detail here http://stackoverflow.com/questions/27351357/getting-android-google-map-v2-working-in-release-version-by-generating-sha1-fing – Eric Barr Dec 08 '14 at 04:25
4

I had this Problem and running these steps I think this way is perfect and complete

For Android Studio:

  1. Build-Generate Signed APK
  2. Copy Key Store Path.
  3. Now open a command prompt and go to C:\Program Files\Java\jdk1.6.0_39\bin> (or any installed jdk version).
  4. Type keytool -list -v -keystore and then paste your Key Store Path (e.g. C:\Program Files\Java\jdk1.6.0_39\bin>keytool -list -v -keystore "E:\My Projects \Android\android studio\signed apks\Hello World\HelloWorld.jks").
  5. Now it will Ask Key Store Password, provide yours and press Enter to get your SHA1 and MD5 Certificate keys.
  6. You Can See SHA1 For Your Debug Certificate and Use in Developer Google Console
Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
JAvAd
  • 114
  • 1
  • 9
2

Sorry for replying late. Hope this helps for future. I use this solution to solve same problem When we are using Google maps while developing, a default debug.keystore is used which has no password. When we build apk file to upload on Play store new SHA-1 key is made so we have to make new debug.keystore for that. We have to create new API key for that SHA-1. According to solution How to obtain Signing certificate fingerprint (SHA1) for OAuth 2.0 on Android? we can get SHA-1 for the exported apk file .

After that use that new API key in Android Manifest as the previous one and you are done.

EDIT 1-
Steps to do this
1) Create apk file using "Use the export Wizard" in "Android Manifest" file of your project.
2) After inserting key and before finishing, MD5 and SHA1 keys are shown as shown is this given pic- (https://i.stack.imgur.com/SldEv.png)
3) Create new API Key for Android project in https://console.developers.google.com for new SHA1 which is retrieved in point 2).
4)Use that API key in manifest file as shown below

5)Clean your project and build APK file again as per point 1).
6) You can see google maps now in that apk.

Community
  • 1
  • 1
Kunal
  • 432
  • 1
  • 4
  • 14
2

There are two things to remember and get this working.

  1. Debug Build Variant

    • Generate a new android debug key using the keytool
    • Associate this key (SHA-1) with the android map api key on google console
    • The debug mode has a google_maps_api.xml where the android maps api key is stored (src/debug/.../google_maps_api.xml) as a string "google_maps_key"
  2. Release Build Variant

    • Generate a new android release key using the keytool
    • Assoiciate this key (SHA-1) with a new android map api key on google console
    • The release mode has a google_maps_api.xml where the release android maps api key is stored (src/release/.../google_maps_api.xml) as a string "google_maps_key".

In the AndroidManifest.xml add the following line :

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

Follow the normal procedure for debug and release. It should work seamlessly.

Anil Muppalla
  • 416
  • 4
  • 14
2

How do I get the release api SHA1 fingerprint:

install your signed APK, from Playstore, or just copying it to the phone.

Plug USB cable if it is a real phone, and open Android Studio.

The first time you try to get maps, a Log entry will show something like:

E/Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)

Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:

API Key: AIzaS<YOUR KEY YOUR KEY YOUR KEY YOUR KEY>

Android Application (<cert_fingerprint>;<package_name>): 56:AF:B2:<THIS IS WHAT YOU ARE LOOKING FOR>;br.com.tinx.<your package>

then, just follow those instructions, creating a new entry in the Developer Console.

  • if you hit your app maps prior seeing the log, you may need to close app from memory and try again)
  • this procedure should work on an emulator too.
WilliamK
  • 1,633
  • 15
  • 12
1
create another Maps API key (to put in your manifest) corresponding with you release   
keystore for release.

check Google's documentation

Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28
1

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

Hussein Alrubaye
  • 915
  • 8
  • 14
1

for futures refs ---my case--- there are two google_maps_api.xml files where you need to put your google api key. You can very easily do the mistake to replace YOUR_API_KEY in only one of them (especially if you just deleted the google api/app and created new ones)

DoruChidean
  • 7,941
  • 1
  • 29
  • 33
  • Yes, that is my case. I have added the SHA-1 to developer console but still not working. Until see this post and realize that there have two google_maps_api.xml, one under debug/res/values and one under release/res/values. – River2202 Mar 10 '16 at 01:03
1

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:

  1. Get SHA1 for the debug using the below command

    keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
    
  2. 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 :)

Atul O Holic
  • 6,692
  • 4
  • 39
  • 74
1

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:

enter image description here

narko
  • 3,645
  • 1
  • 28
  • 33
0

If you are created SHA1 code from custom keystore use the same in release mode. or generate apk by signing with that same keystore and test.

Before that you need clear app data (Setting->App-select app-Clear data->uninstall) and try. this worked for me. Ensure that package name is same as that in google developer console.

Suchith
  • 1,276
  • 17
  • 39
0

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

Javi
  • 629
  • 5
  • 3
0

Below method worked for me:

  • Put google maps api key in manifest as hardcoded text mentioned by @Florence Herrou

Android Studio creates inside:

app\src\debug\res\values\google_maps_api.xml (debug) //add key here

Add key inside ->

app\src\release\res\values\google_maps_api.xml (release) //add key here
Sumit Shukla
  • 4,116
  • 5
  • 38
  • 57
0

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

  • 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.

-> 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.