Problem with Google Maps API key

Asked

Viewed 1,348 times

0

Map does not open on real device using .apk generated.

I made the Activity to the Map using the AS wizard for this purpose, in this mode it generates a SH1. I went to Google API where I already have an account and a project and then generated a key that I put in my project and everything working properly!

With the project finished, I managed a Key Store, I took the SH1 generated a new key, went back to Google API, removed the SHA1 of Debug and I put the new one. I asked to generate a new key but I saw that nothing has changed or that the key was the same!

I managed the .apk and the map does not appear!

I stopped doing something I should? I skipped some stage?

  • Do you display any messages in the Console? Generate the signed apk, and leave the smartphone connected on USB (Debugging, with Android Studio) and see if it displays any key error when opening the screen!

2 answers

2

First to create credentials to access your activated Apis, see the details in the API documentation. Secondly, I’ll give you some tips below:

Create API Key

Step 1: Digital printing for certification SHA-1

To purchase the fingerprint for SHA-1 certification, you have to enter the console of your computer and carry out the following command:

keytool -list -v -Keystore c : Users Mynameuser . android debug.Keystore -alias androiddebugkey -storepass android -keypass android

FORMAT: 5D:C1:0B:2E:E2:91:C3:BB:3E:60:6A:8A:3E:8D:56:C1:0A:C6:36:B2

Step 2: Create your API key

To create your API key, visit the Apis Console on https://code.google.com/apis/console and log in with your Google account.

FORMAT: AIzaSyAi6j8jukil9XnoWzeAsB1Fgr1CQkq9Yk8

Note the image below as seve be configured correctly.

Imagery:

inserir a descrição da imagem aqui

Create Oauth 2.0 Client Ids

You have to generate a Fingerprint of the certificate of authorisation

Add the name of your package and the fingerprint of the certificate login SHA-1 to restrict use to your Android apps. See here.

Note below how it has to be configured:

Imagery:

inserir a descrição da imagem aqui

Despite all configuration, it is important to download the google-services.json made available by Google Console and save inside the APP folder in your project.

In Manifest.xml

Already in your application, you should insert your meta-data's in this way:

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

<meta-data
    android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

PS.: Not forget to grant permission for internet access <uses-permission android:name="android.permission.INTERNET" />

  • Good afternoon, thanks for the comments, as I described I already had a key and everything was ok in the Development environment, I managed a store and from then on I was scolded, what I did was as directed I left the smart in debug mode and I watched the log in AE, what I did now was go to the Google console and generated a new key, using the SHA-1 generated by my Keystore because in the log I can see

  • Robson, you came to generate google-services.json and play inside the app folder?

  • No, this one I didn’t even know my dear, but let continue that I missed here in the previous comment, in the AE log I can see "Google Maps Android API: Authorization Failure" and there in the log I also see the SHA-1 of my Store, generated new key, I put in my manifesto still nothing the error in the AE console is the same, now about this google service json no, nor knew it

  • @Robson This whole procedure I did here in an app of mine published in the store and works perfectly. I came to have this same problem of yours, but then I solved.

  • but in my case, as debug I had no problem, only at the time I sent to the store that did not appear the map. Ai remake everything again following these procedures and funfou bunito.

  • @Robson edited by inserting how you should put in your manifest.xml

  • Dear good afternoon,I found the problem, in my case I generated the map using the AE wizard, it generates a google_maps_api.xml file, only this guy gets in a debug folder of my project, only there’s another guy like this in the release folder, and you don’t see this file and this folder, maybe you didn’t have this problem because you put the key literally in the manifest, so I put the key in the correct file and now it worked, num precisou ai do g-services.json mais obrigado ai a todos.

Show 2 more comments

0

In production, if you use Google Play App Signing, you can easily find the SHA-1 on:

https://play.google.com/apps/publish/ > Click your app > Version management > App subscription > App subscription certificate

Also follow the procedure also by @Viana so that you can use the api in debug mode (by emulator for example)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.