Android: Google Map v2 not showing map for release apk

后端 未结 16 1387
感情败类
感情败类 2020-12-08 16:04

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

相关标签:
16条回答
  • 2020-12-08 16:20

    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.

    0 讨论(0)
  • 2020-12-08 16:21

    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.

    0 讨论(0)
  • 2020-12-08 16:23

    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.

    0 讨论(0)
  • 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)

    0 讨论(0)
  • 2020-12-08 16:29

    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.
    0 讨论(0)
  • 2020-12-08 16:31

    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.

    0 讨论(0)
提交回复
热议问题