简体   繁体   English

无法通过 Debug/Release APK 版本查看地图

[英]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.启用 USB 调试后,我可以在模拟器和我的设备上查看谷歌地图。 But when I try to generate a debug / release apk and install the apk on my device, I am unable to view the maps.但是当我尝试生成调试/发布 apk 并在我的设备上安装 apk 时,我无法查看地图。

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. a) 生成的 API Key in https://console.developers.google.com/并复制到 google_maps_api.xml 的项目中。

b) I have generated the necessary SHA key using the following command. b) 我已经使用以下命令生成了必要的 SHA 密钥。

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?我无法理解的是,如何使用生成的 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/ .根据没有显示谷歌地图的发布 APK 文件,我应该将 SHA 密钥添加到https://console.developers.google.com/上的 API 密钥中。 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:通过安装 apk,然后在模拟器上调试安装的代码,我看到以下异常:

API Key must not be empty.

My google_maps_api.xml is as follows:我的 google_maps_api.xml 如下:

<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.在这里添加了我的 api 密钥--> 这是我添加了我生成的 API 密钥的地方。

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]:我终于能够解决这个问题,这些是我遵循的步骤[在 windows 机器上,在 mac 上应该更容易]:

a) cd into C:\Program Files\Java<jdk version>\bin [or wherever your jdk is installed]. a) cd 进入 C:\Program Files\Java<jdk version>\bin [或安装 jdk 的任何位置]。

b) Run: keytool -list -v -alias -keystore "{keystore ie., .jks file loc}" -storepass {your store password} -keypass {your keypass} b) 运行: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. c) 通过运行 keytool cmd,您的 SHA1 文件将被生成。

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

e) In your project there will be a google_maps_api.xml file. e) 在您的项目中会有一个 google_maps_api.xml 文件。 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}.在此文件中,有一个注释 url,如下所示: https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r={您的项目}%3 包。

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. f) 在上面的链接中,用新生成的密钥替换默认的 SHA1 密钥,然后在您已经登录到谷歌开发者控制台的浏览器上打开链接。

h) Follow the steps as prompted on the browser and with this you should be able to generate an API key. h) 按照浏览器提示的步骤操作,您应该能够生成 API 密钥。

i) Paste the generated API key here: i) 在此处粘贴生成的 API 密钥:

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

This is available on your google_maps_api.xml file.这可在您的 google_maps_api.xml 文件中找到。

j) Now go to {your project location}\app\src\release\res\values and open the google_maps_api file. j) 现在 go 到{your project location}\app\src\release\res\values并打开 google_maps_api 文件。 Here again, replace your API key in the location mentioned in point (i) ie., the code snippet.再次在这里,将您的 API 密钥替换在第 (i) 点中提到的位置,即代码片段。

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 k) 最后 go 到 Android Studio > Your Project > Build > Generate Signed Bundle / APK > {input keystore path and passwords as per point (b)} > Z99938282F04071859941E18F16EFCF42 debug/release

The debug or release apk generated will now allow you to access google maps.生成的调试或发布 apk 现在将允许您访问谷歌地图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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