通过为 API 密钥生成 SHA1 指纹,让 Android Google Map v2 在发布版本中工作 [英] Getting Android Google Map v2 working in release version by generating SHA1 fingerprint for API key

查看:25
本文介绍了通过为 API 密钥生成 SHA1 指纹,让 Android Google Map v2 在发布版本中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今晚我花了很长时间试图弄清楚如何让在我的 Android 应用程序的调试版本中工作的 Google 地图在发布版本中工作.出现了一些不同的问题.Stack Overflow 帖子的一些片段有所帮助,但我认为列出整个过程的更多细节会很有用,包括我遇到的问题,它们是:

I spent a long time tonight trying to figure out how to get my Google Map that worked in the debug version of my Android application to work in the release version. There were a few different problems that came up. Some fragments of Stack Overflow posts helped, but I thought it would be useful to list more detail for the whole process, including the problems I had, which were:

1) 您如何/在哪里为您的发布版本指定不同的内容?

1) How/where do you specify something different for your release version?

2) 您如何运行获取发布版本指纹所需的 keytool 可执行文件?

2) How do you run the keytool executable needed to get the release version fingerprint?

3) 为什么我在运行 keytool 时收到keystore 文件存在但为空"错误?

3) Why was I getting the "keystore file exists but is empty" error when running keytool?

推荐答案

1) 正如其他几篇 Stack Overflow 帖子中所指出的,您可以对调试版本和发布版本使用相同的 Google API 密钥,但您必须提供您在 Google Developers Console 中的调试和发布密钥的指纹.

1) As specified in a couple other Stack Overflow posts, you can use the same Google API key for both your debug and release versions, but you have to supply the fingerprints of your debug and release keys in the Google Developers Console.

  • 登录 Google Developers Console https://console.developers.google.com
  • 选择合适的项目
  • 在左侧,选择API 和身份验证"下的凭据
  • 假设您已经为 Android 应用程序生成了 API 密钥,您应该已经看到您的应用程序列为允许的应用程序"及其调试指纹.点击编辑允许的 Android 应用程序".
  • 您需要为您的应用程序添加另一行,但要使用其发布指纹.为了得到那个......

2) Google 在该对话框中提到您需要运行

2) Google mentions in that dialog that you need to run

keytool -list -v -keystore mystore.keystore

但是通过单击了解更多"并进一步了解,您真正想要运行的是

But by clicking "Learn more" and going a little further, what you really want to run is

keytool -exportcert -alias MY_RELEASE_KEY_ALIAS -keystore MY_FULL_PATH_TO_RELEASE_KEYSTORE_FILE -list -v

然后会要求您输入密钥库密码.文档中没有提到的一个部分是 keytool 程序所在的位置.它在您的 JDK bin 文件夹中.所以在 Windows 上,类似 C:Program FilesJavajdk1.8.0_20in

Then you'll be asked for your keystore password. One piece that isn't mentioned in the docs is where the keytool program is. Its in your JDK bin folder. So on Windows, something like C:Program FilesJavajdk1.8.0_20in

3) 在 Java bin 文件夹中打开控制台窗口并按上述方式运行 keytool 后,我收到一条错误消息,指出密钥库文件存在但为空".最终我意识到,在指定我的发布密钥库文件的完整路径时,我只指定了文件夹名称,但忘记包含实际文件名,即使文件夹中只有一个文件.所以上面的 MY_FULL_PATH_TO_RELEASE_KEYSTORE_FILE 应该包含 .keystore 文件名

3) After I opened a console window in the Java bin folder and ran the keytool as above, I was getting an error that said "keystore file exists but is empty". Eventually I realized that when specifying the full path to my release keystore file, I had only specified the folder name but forgot to include the actual file name, even though there was only one file in the folder. So MY_FULL_PATH_TO_RELEASE_KEYSTORE_FILE above should include the .keystore file name

毕竟,您将最终获得几个指纹,包括 SHA1.您可以复制它,然后返回并将其作为新行粘贴到允许的 Android 应用程序中,最后您的包名用分号分隔,就像调试的一样.

After all that, you will be finally be provided with several fingerprints, including the SHA1. You can copy that, and go back and paste it as a new line in the allowed Android Applications, with your package name on the end separated by a semi-colon, just like the debug one.

这篇关于通过为 API 密钥生成 SHA1 指纹,让 Android Google Map v2 在发布版本中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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