41

I want to generate and use a google API key.

  1. enabled google maps v2 API
  2. created project with one activity with google map (default wizard in studio)
  3. created key on google for debug project, assigned SHA1;app package of application to the project key on google
  4. API key inserted into google_maps_api.xml (AndroidManifest.xml updated automaticaly)
  5. build & run on AVD on which the app is working, map is shown.

Then:

  1. API already enabled
  2. in Android studio created keystore for release (keystore.rel.jks)
  3. generated fingerprints (keytool -list -v -keystore C:\Dropbox\AndroidKeyStore\keystore.rel.jks)
  4. on google added new fingerprint to the new release project (release SHA1;app package) - key generated AIza...
  5. API key inserted into google_maps_api.xml (AndroidManifest.xml updated automatically)
  6. generate signed app (using keystore.rel.jks) & install on real device ... app is working, map is STILL BLANK, only zoom buttons and Google label is on
starball
  • 20,030
  • 7
  • 43
  • 238
morganzd
  • 527
  • 1
  • 4
  • 6

10 Answers10

85

Make sure you enter your release API key in the google_maps_api.xml under the release folder.

First, switch to Project view by using the dropdown in the upper left of the Project Explorer. Then, expand app/src/, and you will see subfolders debug and release. Under there, you should see two separate google_maps_api.xml files under debug/res/values and release/res/values.

Make sure that the release API key is in the google_maps_api.xml file under the release/res/values folder, since this is the one that will be used for the signed release apk.

enter image description here

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
  • 6
    I am not seeing the app\src\debug or app\src\release directories in my project. What would not make them show up? – Spectrem Oct 08 '15 at 00:49
  • 1
    @Spectrem You're probably in Android view in the project explorer. On the upper left there is a dropdown where you can switch to Project view (Take a look at the screenshot directly below TestingMapProject/app/build.gradle). – Daniel Nugent Oct 08 '15 at 01:05
  • Thats what the issue is then. I didnt use the wizard. I have been trying to add a map activity to my current project. Still not sure what part adds the directories though... – Spectrem Oct 08 '15 at 02:39
  • I just copied and pasted those directories from a new project into my current project. – Spectrem Oct 08 '15 at 02:50
  • 1
    @Spectrem I just stumbled across this and have the same problem you had. Did you manually create a `debug` and a `release` folder and add those values? – Ryan Newman Oct 27 '15 at 21:31
  • @RyanNewman Those folders/files are created when using the wizard for new Map Activity or new Map project. – Daniel Nugent Oct 27 '15 at 21:32
  • @DanielNugent, I am having the same issue, although I have written the API key in both release and debug **google_maps_api.xml**, i still get the **Authentication failed on the server.**, but if i run the project directly from android studio i can see the Map – Pankaj Nimgade Nov 26 '15 at 08:07
  • @Spectrem, I am having the same issue, although I have written the API key in both release and debug **google_maps_api.xml**, i still get the **Authentication failed on the server.**, but if i run the project directly from android studio i can see the Map – Pankaj Nimgade Nov 26 '15 at 08:07
13

i was tired of trying over and over again, it turns out that PlayStore has something called App signing certificate, and the map works after i copy that sha1 and paste it in the google console for the android map.

Andres Felipe
  • 4,292
  • 1
  • 24
  • 41
  • 1
    I do not know why you answer was down voted but this was exactly the solution to my problem after have been signed for release and whatever, it turns out that google creates its own signature with its own certificate, and you must use that fingerprint. – Fidel Orozco Aug 16 '18 at 00:13
  • Glad to help you, with this answer, i can't tell you why the downvote – Andres Felipe Aug 16 '18 at 12:12
  • 1
    Thanks @AndresFelipe ! After spending a whole evening figuring out why the googleplay apk didn't worked but all my local configurations did - this finally solved it. – skon Feb 24 '19 at 23:42
  • This article explains `How to Sign your android app with signed key? (private_key.pepk)`: https://learnfreecoding.com/how-to-sign-your-android-app-with-signed-key-private_key-pepk/. That is something you will need (the `private_key.pepk` file) if you choose "Upload a key exported from Android Studio". – Jaime Montoya May 25 '19 at 14:49
  • 1
    Thank you for providing this solution! I was tired of trying over and over again too and your answer was the solution for me. I wrote a more detailed step-by-step process to implement this solution and posted it at https://stackoverflow.com/a/56307654/4242086. Thank you Andrés. – Jaime Montoya May 25 '19 at 18:42
  • after doing this, I had to reinstall my app for the change to take effect. Not a good thing if your app has lots of users – lasec0203 Apr 21 '20 at 19:20
3

When you try to create map api key please make sure the url contain correct package name. It should not take any sub package like this.

wrong package :com.gpslocation.trackerpro.Activities


correct package :com.gpslocation.trackerpro

enter image description here

After editing don't forget to save

Md. Shofiulla
  • 2,135
  • 1
  • 13
  • 19
2

Go to https://play.google.com/apps/publish/ and then to App signing:

enter image description here

Maybe you will see this:

enter image description here

If that is the case, maybe you are a developer and not the account owner. You will have to contact the account owner and ask him/her to complete that process. Follow this article about how to do that:

https://learnfreecoding.com/how-to-sign-your-android-app-with-signed-key-private_key-pepk/

The account owner will get to this screen:

enter image description here

Ask them to choose Upload a key exported from Android Studio. They will have to upload a private_key.pepk file. This is how you get that file from Android Studio:

  • Go to Build > Generate Signed Bundle / APK....

enter image description here

Select Android App Bundle and click Next:

enter image description here

Provide the corresponding credentials and make sure to put the check on for Export encrypted key for enrolling published apps in Google Play App Signing.

enter image description here

Specify the destination folder and make sure you select release before you click Finish:

enter image description here

That will generate the private_key.pepk file that you need to provide to Upload a key exported from Android Studio.

After doing the above, when you to to the App signing section of your app, you will see something like this:

enter image description here

Then you will see the Google Maps working correctly on real Android Studio physical devices and not only on the Android Studio Emulator. This was the solution for me.

Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103
1

generally you must do below steps:

1- Create New maps Activity in android studio

2- In google_maps_api.xml open the link in line 3

3- Confirm data and get key in Firebase

4- Copy key in google_maps_api.xml debug and release

5- Get release SHA1 in gradle tab -> signing report

useful link for get sha1

useful link for sign application in debug mode to get sha1

masoud jafari
  • 522
  • 9
  • 14
1

Make sure you enable the Maps for Android app in Google Console.

Wise Shepherd
  • 2,228
  • 4
  • 31
  • 43
0

Make sure the map key you entered in google_maps_api.xml file is the same android key, generated by google console.

You can also try a new key.

shehzy
  • 2,215
  • 3
  • 25
  • 45
0

Got stuck on this issue for a day. I tried everything and eventually found the following code in my manifest:

<supports-screens
   android:anyDensity="false"
   android:largeScreens="true"
   android:normalScreens="true"
   android:smallScreens="false"
   android:xlargeScreens="true" />

After removing these lines my maps displayed correctly.

Full-Fledged
  • 309
  • 2
  • 8
0

enter image description hereI faced the same problem, in my case fingerprint of my package used in google map API key was mismatched so what i did:

  • Create a new google map activity.
  • Go to google_maps_api.xml.
  • Copy the link given in that file in paste in browser(login to google account).
  • On google create some project here and press continue
  • Click on create API key
  • Copy the key and paste in google_maps_api.xml

    string name="google_maps_key" templateMergeStrategy="preserve" translatable="false"YOUR KEY HERE

And execute the application

Do not use below fingerprint, or key, create your separate it is based on package ans application

vijaycaimi
  • 317
  • 1
  • 2
  • 6
0

Please follow these steps:

  1. Go to Google Play Console -> Setup -> App integrity -> App signing key certificate
  2. Copy the SHA-1 certificate fingerprint
  3. Open Google Cloud Platform
  4. Go to APIs & Services -> Credentials
  5. Click on your API key
  6. Go to Application restrictions -> Restrict usage to your Android apps
  7. Click on ADD AN ITEM
  8. Add your package name with the copied SHA-1 certificate fingerprint
  9. Wait for around 10 mins. and your maps would be visible on your published app.

enter image description here

enter image description here

Sweta Jain
  • 3,248
  • 6
  • 30
  • 50