【问题标题】:Android Maps SDK for Android Not Working in Release适用于 Android 的 Android 地图 SDK 在发行版中不工作
【发布时间】:2021-09-16 10:34:20
【问题描述】:

我的 Android 应用已经在 Play 商店上架了几年。我最近为其添加了 Google 地图功能。

如果我不限制应用程序,则映射 sdk 和活动可以正常工作。我将 Google Cloud Platform (console.cloud.google.com) 生成的 API Key 放入我的应用中,一切正常。

但将此密钥仅限于我的应用程序似乎是合理的。这需要为您的应用生成 SHA-1 证书并将其与您的包名称一起保存到 Google Cloud Platform。

在 Android Studio 终端窗口中,我执行以下命令:

keytool -list -v -keystore your_keystore_name -alias your_alias_name

使用我的 build.gradle (app) 文件中指定的“your_keystore_name”。

奇怪的是,无论我是否指定“-alias your_alias_name”,它似乎都会生成相同的 SHA-1 证书。这听起来对吗?

回到谷歌云平台,我点击Restrict to Android App并添加SHA-1和我的包名,然后点击保存。

当我以这种方式进行限制时,我的应用程序上的地图视图将停止工作并显示空白/灰色屏幕。当我解除限制后,它又开始工作了。

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com....">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

    <application
        ...>

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

build.gradle(应用程序)

apply plugin: 'com.android.application'

android {
    signingConfigs {
        debug {
            storeFile file(var)
            storePassword '...'
            keyAlias = '...'
            keyPassword '...'
        }
        release {
            storeFile file(var)
            storePassword '...'
            keyAlias = '...'
            keyPassword '...'
        }
    }
dependencies {
    :    :
    implementation 'com.google.android.gms:play-services-location:18.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
    implementation 'com.google.android.gms:play-services-maps:17.0.1'
    :    :
}

activity_maps.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity" />

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    我与 Google Cloud Platform 支持部门就这个问题合作了几天。在与一个低级别的支持人员毫无进展后,我要求升级。这很快就完成了,没有消极情绪。 Google 支持万岁。

    升级级别支持很快解决了这个问题。我最初(2 年前)使用“Google Play 应用签名”在 Play 商店中设置了我的应用。

    因此,如果您使用 Google Play 应用签名进行发布,您可以从 Google Play 控制台的发布 > 设置 > 应用完整性 页面获取您的 SHA-1。不是通过执行 keytool... 命令。

    一旦我将此 SHA-1 应用于我在 Google Cloud Platform 上的应用程序限制,一切正常。

    【讨论】:

      猜你喜欢
      • 2019-04-22
      • 2022-08-24
      • 2013-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多