Google Places for Android API 密钥不适用于 Play 商店中的应用 [英] Google Places for Android API key does not work on app from Play Store

查看:52
本文介绍了Google Places for Android API 密钥不适用于 Play 商店中的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近推出了一款 Android 应用它利用了 Google Places 自动完成小部件/API.作为此配置的一部分,我将 API 密钥添加到我的 Android 清单文件中:

I recently launched an Android app which makes use of the Google Places autocomplete widget/API. As part of the configuration for this, I added the API key to my Android's manifest file:

<application>
    ...
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="MY_KEY_HERE"/>
</application>

此外,在 Google Developers 控制台中,我仅为 Android 设备启用了此 API 密钥,但并未限制为任何特定 API.我还为我的应用程序输入了正确的包名和 SHA-1 哈希值.现在我有以下问题:

Furthermore, in the Google Developers console, I enabled this API key for Android devices only, but did not restrict to any particular API. I also entered the correct package name and SHA-1 hash for my app. Now I have the following problem:

  • 当我直接从 Android Studio 将应用部署到 Android 手机上时,Google API 都能正常工作.无论我使用调试模式还是发布模式,都是如此.
  • 当我将 APK 从完全相同的代码发布到 Play 商店,然后安装该应用程序时,除了 Google 自动完成 API 损坏之外,一切正常.尝试访问它时,它会立即关闭.

我确信我部署到 Play 商店的实际上是在本地运行的同一个应用程序,因为我最近还做了一些小的 UI 补丁,这些补丁也出现在商店版本中.我多次验证,正确的密钥是出现在清单文件中的内容.

I am certain that what I deployed to the Play Store is in fact the same app running locally, because I had also recently made some minor UI patches, and those also showed up on the store version. I verified several times that the correct key is what appears in the manifest file.

我无法解释这一点.这个问题特别困难,因为一切都在 Android Studio 中运行,所以我不能做一些像进入调试并尝试捕获异常的事情.

I am at a loss to explain this. This problem is particularly difficult because everything works from Android Studio, so I can't do something like go into debug and try to catch an exception.

如果您对 Android 和自动完成有一定的了解,并且遇到过类似的问题,那么我欢迎您的回答.

If you have some expertise with Android and autocomplete, and you have seen a problem similar to this, then I welcome your answer.

推荐答案

@NullPointer 的答案在功能上是正确的,确实解决了我的问题.但为了更直接地回答我自己的问题,问题的根本原因与为 Android 应用的本地调试版本和同一应用的发布版本配置 Google API 的过程截然不同.

The answer by @NullPointer is functionally correct, and does indeed fix my problem. But to give a more direct answer to my own question, the root cause of the problem has to do with substantially different procedures for configuring Google APIs for a local debug version of an Android app and a release version of the same app.

这里的部分混乱与 Google 控制台本身有关,它说:

Part of the confusion here has to do with the Google console itself which says:

然后使用以下命令获取(SHA-1)指纹:

Then use the following command to get the (SHA-1) fingerprint:

keytool -list -v -keystore mystore.keystore

在本地构建和测试应用程序时,在调试模式下,实际上针对调试密钥库文件运行 keytool,并将 SHA-1 哈希粘贴到 Google 控制台将使 API 工作.在代码库上坐了几个月或更长时间,并且 API 看起来非常稳定之后,当对发布版 APK 重复这些步骤时,接下来会发生什么令人惊讶.

When building and testing an app locally, in debug mode, in fact running keytool against the debug keystore file, and pasting the SHA-1 hash into the Google console will get the API to work. After sitting on a codebase for several months, or longer, and the APIs appearing to be very stable, it then comes as a surprise what happens next when repeating these steps with the release APK.

令人惊讶,因为遵循相同的步骤不适用于发布应用.这是因为 Google Play 商店实际上使用不同的密钥退出了您的 APK,因此具有不同的 SHA-1 哈希值.要找到需要使用的 SHA-1 哈希值,可以访问 Release management ->Google Play 控制台中的应用签名.在发布您的应用程序并等待 10-15 分钟以使其刷新后执行此操作.然后,只需将此 SHA-1 粘贴回 Google API 控制台即可.

It is a surprise, because following the same steps won't work for the release app. This is because the Google Play Store actually resigns your APK with a different key, which therefore has a different SHA-1 hash. To find the SHA-1 hash which needs to be used, one may visit Release management -> App signing in the Google Play console. Do this after publishing your app and waiting perhaps 10-15 minutes for it to refresh. Then, just paste this SHA-1 back into the Google API console, and off you go.

顺便说一下,我的问题非常类似于 Play Store 上发布的应用程序无法与 Google Maps API 和 Facebook API 通信,尽管没有过多强调为什么 Google API 可能在调试模式下工作,但不是在 Play 商店.顺便说一句,我感谢@RohitChauhan,他粘贴了一条评论,其中包含指向此问题的链接.

By the way, my question is very similar to Published App on Play Store can't communicate with Google Maps API and Facebook API, though not much emphasis was given there for why a Google API might be working in debug mode, but not on the Play Store. Incidentally, I give credit to @RohitChauhan who pasted a comment containing a link to this question.

这篇关于Google Places for Android API 密钥不适用于 Play 商店中的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆