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

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

问题描述

我最近推出了Android应用该工具利用了Google地方信息的自动填充小部件/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都可以使用.无论我使用的是debug还是release模式,都是如此.
  • 当我使用完全相同的代码将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哈希,可以在Google Play控制台中访问Release management -> App signing.在发布您的应用并等待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.

顺便说一句,我的问题与

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天全站免登陆