Android: Google Map v2 not showing map for release

2019-01-17 07:37发布

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.

14条回答
Emotional °昔
2楼-- · 2019-01-17 08:12
create another Maps API key (to put in your manifest) corresponding with you release   
keystore for release.

check Google's documentation

查看更多
再贱就再见
3楼-- · 2019-01-17 08:13

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.
查看更多
混吃等死
4楼-- · 2019-01-17 08:16

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.

查看更多
叼着烟拽天下
5楼-- · 2019-01-17 08:18

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
查看更多
狗以群分
6楼-- · 2019-01-17 08:19

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- (http://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.

查看更多
神经病院院长
7楼-- · 2019-01-17 08:19

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.

查看更多
登录 后发表回答