所以我在我的应用程序中使用谷歌地图 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
关于java - 生成 Google map 发布 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33055735/