无法转换Android Studio项目的新API密钥

问题描述 投票:1回答:1

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

该项目起源于我的桌面,我有一段时间没有更新android studio。我把这个项目加载到运行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>

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

android google-maps-markers google-maps-android-api-2
1个回答
-1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.