转换 Android Studio 项目新 API 密钥时遇到问题



我在2018年做了一个使用Android Google Maps SDK的项目,它基本上是一个地理定位器。我现在正在尝试重新启动该项目,但是Google已经更改了如何在程序中实现API密钥。有谁知道在2019年将API密钥添加到Android Studio项目的传统方法。版本 3.3.

该项目起源于我的桌面,我已经有一段时间没有更新 android 工作室了。我接受了这个项目,并将其加载到运行Android Studio 3.3的笔记本电脑上。它构建完美,功能完美,除了地图只会显示谷歌水印。

我现在实际上把钥匙放在哪里?我读到它应该在gradle.properties中,但也在其他地方。那么,让它起作用的传统方法是什么?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.tommy.app">
    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />
        <activity
            android:name=".MapSearch"
            android:label="@string/title_activity_map_search">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.tommy.app.MainActivity" />
        </activity>
        <activity
            android:name=".Map2"
            android:label="@string/title_activity_map2"></activity>
    </application>
</manifest>

地图应对在第一个活动中输入的位置进行地理定位。

如果您在将项目计算机移植到计算机时遇到问题,只需通过 Google Cloud Development 转到 API 密钥凭据,找到您最初使用的密钥,为同一项目名称添加新的限制,但使用新的 SHA1(来自新 PC(。查找密钥库以查找您的 SHA。

相关内容

最新更新