java - 生成 Google map 发布 key

标签 java google-maps android-studio

所以我在我的应用程序中使用谷歌地图 API。我添加了 Activity 并将 api key 放入 google_maps_api.xml(debug) 中,然后创建了一个不同的 api key 并将其放入/release 下的 google_maps_api.xml 中,我必须转到文件资源管理器才能找到它。如果我通过 android studio 中的绿色播放按钮启动应用程序, map 加载得很好。但是当我在构建下生成 apk 时, map 无法加载。我相信这是由于 api 不工作造成的。我担心的问题之一是编辑 google_maps_api(release) 的唯一方法是在资源管理器中找到它。非常感谢所有帮助!

这是 list :

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

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

    <application
        android:allowBackup="true"
        android:fullBackupContent="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <service android:name=".GeofenceTransitionsIntentService" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="android.app.default_searchable"
                android:value=".SearchableActivity" />
        </activity>
        <activity
            android:name=".SettingsActivity"
            android:label="@string/Settings"
            android:parentActivityName=".MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".ViewCodeActivity"
            android:label="Receipt Code"
            android:parentActivityName=".MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity" />
        </activity>
        <activity
            android:name=".GetHelp"
            android:label="@string/get_help_title"
            android:parentActivityName=".SettingsActivity" >
            <meta-data
                android:name="android.support.PARENT.ACTIVITY"
                android:value=".SettingsActivity" />
        </activity>
        <activity
            android:name=".CodeAdder"
            android:label="@string/title_activity_code_adder"
            android:parentActivityName=".MainActivity"
            android:theme="@style/AppTheme.NoActionBar" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.nick.mowen.receiptmanager.MainActivity" />
        </activity>
        <activity android:name=".SearchActivity" >
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
            </intent-filter>

            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable" />
        </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=".LocationPicker"
            android:label="@string/title_activity_location_picker" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.nick.mowen.receiptmanager.CodeAdder" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这是 build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.nick.mowen.receiptmanager"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.android.support:recyclerview-v7:23.0.1'
    compile 'com.google.android.gms:play-services-maps:8.1.0'
    compile 'com.google.android.gms:play-services:8.1.0'
}

最佳答案

您可以使用相同的 Android API key 进行调试和发布。

包名称可以相同,但由于您无法使用调试 keystore 对版本进行签名,因此证书指纹应该不同

使用 keytool 命令检查释放指纹是否正确:

keytool -list -v -keystore my_release_store.keystore

Multiple entries for the same Android API key

关于java - 生成 Google map 发布 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33055735/

相关文章:

java - 使 ActionHandler 忽略箭头键

ios - 从 GMSMapView 隐藏地铁站

flutter - Android Studio 不显示项目文件

java - 如何正确地将多个TextView放置在imageView上

java - 如何在 RichFaces 中选择所有同类元素

java - Android WebRTC - 为 session 混合音轨

java - Jvm错误java.lang.UnsupportedClassVersionError :

javascript - Google map /地点地理编码

google-maps - 调整谷歌地图标记的 svg 图标大小

android - 更新 SDK 后,Pixel 启动器一直停止