问题
I'm currently developing an application for Android and I'm using Google Maps API. In developer console, I added my SHA1 certificate print, followed by my package name. Even though I put this SHA1 certificate print using keytool, I can't access to the maps. I made lots of search, but every topics brought me to answers where error were in a wrong API Key in developer console. But I took the right SHA1, the one of my certificate.
Thanks in advance !
回答1:
I had this same problem, it was super frustrating. What I ended up doing was taking the key I made using my release keystore and putting it in the google developers console. Then, added the following into the android manifest.
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="KEY GOES HERE"/>
I'm sure you read the documentation on this, but make sure you follow the instructions for the release certificate to the dot.
https://developers.google.com/maps/documentation/android/signup
You could also follow the link that was generated for you in the google_maps_api.xml file. This automates the process of entering the key into the developer console. However, make sure you still add that meta data value into your manifest.
回答2:
My Map in release mode was showing but after I publish to Play Store it was not showing.
I had mentioned both debug and release certificate SHA-1 Key to Google Developer Console but map in release mode after downloading app from play store was still not showing.
Here' what was problem: Google Play App Signing is enabled for this app
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.
回答3:
The file google_maps_api.xml has to be under res/debug/ and res/release. The editor only shows your current run configuration which is debug by default and is a bit misleading if you do not observe the (debug) note after the folder name. Copy the google_maps_api.xml into both folder and edit make sure they have the correct API keys ofr each build.
回答4:
Android Studio also creates a TODO in the release folder for the google_maps_api xml file and lets you know of the required procedure before release. Also please do not change the key in manifest manually. When you switch to a release variant, the key is automatically updated in the manifest.
In any case do this,
Go to the link as mentioned by @Andrew Brook
Click "Get a key" and continue
- Either create a new project or use an existing one
- Specify the options and click the button
- If you already had made one before, for let's say for debug, then go to Create a new api key Image here
- Add the required name, click on "Add package name and fingerprint"
- Add your app's package name and SHA-1 key (generete it using keytool in java/jdk../bin/) Image here
- You get your "release" variant API key to be added in the google_maps_api.xml in the release folder.
回答5:
You have to Enable the SHA key In Google Developer Console so at 1st go to release Management get your app SHA key (1st one ) then Follow this link
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=(Your SHA KEY)%3B(YOUR PACKAGE NAME)
Now it Will Enable the API . now update your app with the new key . It will Work .
来源:https://stackoverflow.com/questions/31834433/google-maps-api-key-in-release-build-doesnt-work