Google 使用正确密钥的 Maps V2 无法在生产环境中运行
Google Maps V2 not working in production with correct key
我在让 Google 地图在 Android 应用程序中投入生产时遇到了很大的麻烦。这是我目前得到的(底部只是广告)。
我遵循的关键步骤:
1) 我已确保我获得了正确的 SHA1 生产密钥,并已在 Google 控制台 API 以及应用程序中实施了它(他们键入 google给)。我已经注册了两个密钥 - 一个用于调试,一个用于生产
2) 互联网、位置等正常工作
3) 该应用程序可在 DEBUG 模式下运行,但在通过 USB 签名并安装到设备时无法运行。我已经三次检查了标志的 SHA 1 签名等
4) MapsFragment 来自 Android Studio 中可用的模板。
在生产模式下,日志猫显示如下:
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
这个错误显然是说我的授权有问题?
我做错了什么?
调试密钥和生产密钥会不同。如果您使用调试密钥用于发布模式,您将无法查看 google 地图。对于发布模式,当您更改 google 映射键时,您应该清理项目然后导出 apk。
您可以获得更多信息
https://developers.google.com/maps/documentation/android/start
从调试密钥存储中获取私有 SHA1
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass your_app_password
查看更多
SHA-1 fingerprint of keystore certificate
或者您可以使用导出菜单生成 SHA1 私钥的 eclipse 工具
基于可调试发布版本的 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
您似乎没有覆盖清单中的 api 密钥占位符 YOUR_KEY_HERE
(或单独的 api 密钥文件,具体取决于您的配置)。用您的实际密钥替换该字符串,无论它位于何处,您应该一切顺利。
编辑:this tutorial,如果它与您的配置匹配,可能解释了为什么您只看到发布版本:
Return to Android Studio and paste the API key into the YOUR_KEY_HERE section of the file:
Note that these steps have enabled Google Maps support for the debug version of the application package. The API key will also need to be added to the google_maps_api.xml file located in MapDemo -> app -> src -> release -> res -> values when the release version of the application is ready to be built.
当使用 Android Studio 生成 Google 地图 Activity 时,它将忽略您的 gradle 构建配置并使用默认 debug.keystore
。 google_maps_api.xml
中的 SHA1 基于此默认值。在 Google API 控制台中创建权限时,如果使用非默认设置,请确保使用生产和调试 SHA1。
我遇到了同样的问题,这几天一直在用头撞墙。我阅读了所有关于将正确的密钥放在适当位置的帖子。我一直将正确的密钥放入我的 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" />
并在 google_maps_api.xml 中:
<string name="google_maps_key"
templateMergeStrategy="preserve"
translatable="false">AIza_the actual key</string>
为了让它工作我更改了什么
我将 AndroidManifest.xml 更改为包括:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzsa_the actual key" />
就我而言,我在 Google API 的 API 管理器 - 凭据 - "Restrict usage to your Android apps" 中输入了错误的包名称。确保输入正确的包名称(如 AndroidManifest.xml)和正确的 SHA 指纹(用于调试和生产)。
已解决,我将"Key for browser apps (with referers)"而不是GoogleAPI控制台
中的"Key for Android apps (with certificates)"放在清单上
在我的例子中,灰屏是由于 HostnameVerifier
的自定义实现阻止加载图块造成的。
希望这对以后的其他人有所帮助。
error //确保启用"Google Maps Android API v2"。
在此您无法在 Google Cloud Platform Console 中找到 Google Maps Android API v2。in this, give the exact Package Name: and signature of your project which is showing in run window or debug window , I faced the same problem because of changing MapActivity package location
我整天都在努力寻找这一点,所以请确保您是否更改了项目中的任何包,如果是的话,请提供错误文本中显示的包
强调文字
确保存在以下 Android 键:
API 键:YOUR_KEY_HERE
Android 应用 (;): ;com.mike.mapstest
我在让 Google 地图在 Android 应用程序中投入生产时遇到了很大的麻烦。这是我目前得到的(底部只是广告)。
我遵循的关键步骤:
1) 我已确保我获得了正确的 SHA1 生产密钥,并已在 Google 控制台 API 以及应用程序中实施了它(他们键入 google给)。我已经注册了两个密钥 - 一个用于调试,一个用于生产
2) 互联网、位置等正常工作
3) 该应用程序可在 DEBUG 模式下运行,但在通过 USB 签名并安装到设备时无法运行。我已经三次检查了标志的 SHA 1 签名等
4) MapsFragment 来自 Android Studio 中可用的模板。
在生产模式下,日志猫显示如下:
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
这个错误显然是说我的授权有问题? 我做错了什么?
调试密钥和生产密钥会不同。如果您使用调试密钥用于发布模式,您将无法查看 google 地图。对于发布模式,当您更改 google 映射键时,您应该清理项目然后导出 apk。
您可以获得更多信息 https://developers.google.com/maps/documentation/android/start
从调试密钥存储中获取私有 SHA1
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass your_app_password
查看更多
SHA-1 fingerprint of keystore certificate
或者您可以使用导出菜单生成 SHA1 私钥的 eclipse 工具
基于可调试发布版本的 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
您似乎没有覆盖清单中的 api 密钥占位符 YOUR_KEY_HERE
(或单独的 api 密钥文件,具体取决于您的配置)。用您的实际密钥替换该字符串,无论它位于何处,您应该一切顺利。
编辑:this tutorial,如果它与您的配置匹配,可能解释了为什么您只看到发布版本:
Return to Android Studio and paste the API key into the YOUR_KEY_HERE section of the file:
Note that these steps have enabled Google Maps support for the debug version of the application package. The API key will also need to be added to the google_maps_api.xml file located in MapDemo -> app -> src -> release -> res -> values when the release version of the application is ready to be built.
当使用 Android Studio 生成 Google 地图 Activity 时,它将忽略您的 gradle 构建配置并使用默认 debug.keystore
。 google_maps_api.xml
中的 SHA1 基于此默认值。在 Google API 控制台中创建权限时,如果使用非默认设置,请确保使用生产和调试 SHA1。
我遇到了同样的问题,这几天一直在用头撞墙。我阅读了所有关于将正确的密钥放在适当位置的帖子。我一直将正确的密钥放入我的 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" />
并在 google_maps_api.xml 中:
<string name="google_maps_key"
templateMergeStrategy="preserve"
translatable="false">AIza_the actual key</string>
为了让它工作我更改了什么 我将 AndroidManifest.xml 更改为包括:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzsa_the actual key" />
就我而言,我在 Google API 的 API 管理器 - 凭据 - "Restrict usage to your Android apps" 中输入了错误的包名称。确保输入正确的包名称(如 AndroidManifest.xml)和正确的 SHA 指纹(用于调试和生产)。
已解决,我将"Key for browser apps (with referers)"而不是GoogleAPI控制台
中的"Key for Android apps (with certificates)"放在清单上在我的例子中,灰屏是由于 HostnameVerifier
的自定义实现阻止加载图块造成的。
希望这对以后的其他人有所帮助。
error //确保启用"Google Maps Android API v2"。 在此您无法在 Google Cloud Platform Console 中找到 Google Maps Android API v2。in this, give the exact Package Name: and signature of your project which is showing in run window or debug window , I faced the same problem because of changing MapActivity package location 我整天都在努力寻找这一点,所以请确保您是否更改了项目中的任何包,如果是的话,请提供错误文本中显示的包 强调文字 确保存在以下 Android 键: API 键:YOUR_KEY_HERE Android 应用 (;): ;com.mike.mapstest