简体   繁体   中英

Unable to view Maps with Debug/Release APK release

I am able to view google maps on Emulators and on my device when USB debugging is enabled. But when I try to generate a debug / release apk and install the apk on my device, I am unable to view the maps.

I have done the following:

a) Generated API Key in https://console.developers.google.com/ and have copied it into google_maps_api.xml of my project.

b) I have generated the necessary SHA key using the following command.

keytool.exe -list -v -alias <myalias> -keystore <my path> -storepass <passwd> -keypass <passwd>

What I am not able to understand is, how do I use the generated SHA?

As per Release APK file not showing google maps I am supposed to add the SHA key into my API key on https://console.developers.google.com/ . But, I see no such option to add it.

By installing the apk and then debugging the installed code on an emulator, I see the following exception:

API Key must not be empty.

My google_maps_api.xml is as follows:

<resources>
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">Have added my api key here</string>

Have added my api key here --> This is where I have added the API ket that I have generated.

Have added this into my manifest file:

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

Can someone help me out in understanding what is it that I am supposed to do?

I was finally able to fix this issue and these were the steps I followed [on a windows machine, should be much more easier on a mac]:

a) cd into C:\Program Files\Java<jdk version>\bin [or wherever your jdk is installed].

b) Run: keytool -list -v -alias -keystore "{keystore ie., .jks file loc}" -storepass {your store password} -keypass {your keypass}

c) By running the keytool cmd, your SHA1 file would then be generated.

d) Login to https://console.developers.google.com/

e) In your project there will be a google_maps_api.xml file. In this file there is a commented url, something like this: https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r={your SHA1 key}%3B{your project package}.

f) In the link above, replace the default SHA1 key with the newely generated key and open the link on a browser from where you already have logged into google develover console.

h) Follow the steps as prompted on the browser and with this you should be able to generate an API key.

i) Paste the generated API key here:

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">API key</string>

This is available on your google_maps_api.xml file.

j) Now go to {your project location}\app\src\release\res\values and open the google_maps_api file. Here again, replace your API key in the location mentioned in point (i) ie., the code snippet.

k) Finally go to Android Studio > Your Project > Build > Generate Signed Bundle / APK > {input keystore path and passwords as per point (b)} > select debug/release version > Finish

The debug or release apk generated will now allow you to access google maps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM