Google Maps V2无法使用正确的密钥在生产环境中工作

For*_*ing 29 android google-maps

我在使用Android应用程序生产谷歌地图时遇到了重大麻烦.这就是我目前得到的(底部只是广告).

应用生产屏幕

我遵循的关键步骤:

1)我已经确保我已经获得了正确的SHA1生产密钥,并且已经在Google Console API和应用程序中实现了它(谷歌提供的密钥).我已经注册了两个键 - 一个用于调试,一个用于生产

2)互联网,位置等正在运作

3)该应用程序在DEBUG模式下工作,但在通过USB签名并安装在设备上时不起作用.我已经三次检查了标志的SHA 1签名等.

4)MapsFragment来自Android Studio中提供的模板.

在生产模式下,log cat显示:

01-11 16:04:54.511  19346-19437/com.mike.mapstest E/Google Maps Android API? Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
01-11 16:04:54.516  19346-19437/com.mike.mapstest E/Google Maps Android API? In the Google Developer Console (https://console.developers.google.com)
    Ensure that the "Google Maps Android API v2" is enabled.
    Ensure that the following Android Key exists:
    API Key: YOUR_KEY_HERE
    Android Application (<cert_fingerprint>;<package_name>): <SHA1 Removed for this> ;com.mike.mapstest
Run Code Online (Sandbox Code Playgroud)

这个错误显然表明我的身份证明有问题吗?我究竟做错了什么?

stk*_*ent 42

基于debuggable发布版本的logcat输出:

01-11 16:04:54.511  19346-19437/com.mike.mapstest E/Google Maps Android API? Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
01-11 16:04:54.516  19346-19437/com.mike.mapstest E/Google Maps Android API? In the Google Developer Console (https://console.developers.google.com)
    Ensure that the "Google Maps Android API v2" is enabled.
    Ensure that the following Android Key exists:
    API Key: YOUR_KEY_HERE
    Android Application (<cert_fingerprint>;<package_name>): <SHA1 Removed for this> ;com.mike.mapstest
Run Code Online (Sandbox Code Playgroud)

您似乎没有覆盖YOUR_KEY_HERE清单中的api密钥占位符(或单独的api密钥文件,具体取决于您的配置).用你的实际钥匙替换那根绳子,无论它住在哪里,你都应该好好去.

编辑:本教程,如果它符合您的配置,可能解释了为什么您只看到发布版本的原因:

返回Android Studio并将API密钥粘贴到文件的YOUR_KEY_HERE部分:

请注意,这些步骤已启用Google Maps支持应用程序包的调试版本.当准备构建应用程序的发布版本时,还需要将API密钥添加到位于MapDemo中的google_maps_api.xml文件 - > app - > src - > release - > res - > values中.

  • 谢谢@stkent.这就是问题所在.似乎必须将API密钥硬编码到清单中,而不是使用外部XML文件中的字符串资源. (5认同)
  • 好的,我找到了解决方案.第一:密钥必须硬编码第二:当我生成KEY我使用密钥; packagename模板时,Android工作室在google_maps_api.xml的评论部分为我生成了什么.是的......包装名称属于碎片,而不是最主要的包装.这会杀死所有东西,当我用清单中的那个切换它时,它没关系.生成API密钥时,请确保在GoogleConsole上使用密钥; manifestpackage模板@DroidWormNarendra (2认同)

小智 9

我遇到了同样的问题,并且正在将我的头撞在墙上几天.我阅读了关于正确放置钥匙的所有帖子.我一直在google_maps_api.xml文件中输入正确的密钥.上面提到的StKent确保用AndroidManifest.xml中的实际字符串覆盖.这就是为我解决的问题.

它没有用的东西: 在AndroidManifest.xml中:

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />
Run Code Online (Sandbox Code Playgroud)

并在google_maps_api.xml中:

 <string name="google_maps_key"
        templateMergeStrategy="preserve"
        translatable="false">AIza_the actual key</string>
Run Code Online (Sandbox Code Playgroud)

我改变了它的工作方式 我将AndroidManifest.xml更改为包括:

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzsa_the actual key" />
Run Code Online (Sandbox Code Playgroud)