java生成Google地图发布密钥
所以我在我的应用程序中使用谷歌地图api。我添加了活动,并将api密钥放入google_maps_api。然后创建了一个不同的api密钥,并将其放入google_maps_api。xml在/release下,我必须去文件浏览器找到它。如果我在安卓 studio中通过绿色的play按钮启动应用程序,地图加载就可以了。但当我在构建下生成apk时,地图不会加载。我相信这是因为api不起作用。我担心的一个问题是,编辑google_maps_api(发布版)的唯一方法是在浏览器中找到它。非常感谢您的帮助
以下是清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
package="com.nick.mowen.receiptmanager" >
<uses-permission 安卓:name="安卓.permission.ACCESS_FINE_LOCATION" />
<uses-permission 安卓:name="安卓.permission.INTERNET" />
<uses-permission 安卓:name="安卓.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission 安卓:name="安卓.permission.READ_EXTERNAL_STORAGE" />
<uses-permission 安卓:name="安卓.permission.ACCESS_COARSE_LOCATION" />
<application
安卓:allowBackup="true"
安卓:fullBackupContent="true"
安卓:icon="@mipmap/ic_launcher"
安卓:label="@string/app_name"
安卓:theme="@style/AppTheme" >
<service 安卓:name=".GeofenceTransitionsIntentService" />
<activity
安卓:name=".MainActivity"
安卓:label="@string/app_name" >
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
安卓:name="安卓.app.default_searchable"
安卓:value=".SearchableActivity" />
</activity>
<activity
安卓:name=".SettingsActivity"
安卓:label="@string/Settings"
安卓:parentActivityName=".MainActivity" >
<meta-data
安卓:name="安卓.support.PARENT_ACTIVITY"
安卓:value=".MainActivity" />
</activity>
<activity
安卓:name=".ViewCodeActivity"
安卓:label="Receipt Code"
安卓:parentActivityName=".MainActivity" >
<meta-data
安卓:name="安卓.support.PARENT_ACTIVITY"
安卓:value=".MainActivity" />
</activity>
<activity
安卓:name=".GetHelp"
安卓:label="@string/get_help_title"
安卓:parentActivityName=".SettingsActivity" >
<meta-data
安卓:name="安卓.support.PARENT.ACTIVITY"
安卓:value=".SettingsActivity" />
</activity>
<activity
安卓:name=".CodeAdder"
安卓:label="@string/title_activity_code_adder"
安卓:parentActivityName=".MainActivity"
安卓:theme="@style/AppTheme.NoActionBar" >
<meta-data
安卓:name="安卓.support.PARENT_ACTIVITY"
安卓:value="com.nick.mowen.receiptmanager.MainActivity" />
</activity>
<activity 安卓:name=".SearchActivity" >
<intent-filter>
<action 安卓:name="安卓.intent.action.SEARCH" />
</intent-filter>
<meta-data
安卓:name="安卓.app.searchable"
安卓: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
安卓:name="com.google.安卓.geo.API_KEY"
安卓:value="@string/google_maps_key" />
<activity
安卓:name=".LocationPicker"
安卓:label="@string/title_activity_location_picker" >
<meta-data
安卓:name="安卓.support.PARENT_ACTIVITY"
安卓:value="com.nick.mowen.receiptmanager.CodeAdder" />
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
这是构建。格雷德尔:
apply plugin: 'com.安卓.application'
安卓 {
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-安卓.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.安卓.support:appcompat-v7:23.0.1'
compile 'com.安卓.support:design:23.0.1'
compile 'com.安卓.support:recyclerview-v7:23.0.1'
compile 'com.google.安卓.gms:play-services-maps:8.1.0'
compile 'com.google.安卓.gms:play-services:8.1.0'
}
# 1 楼答案
如果您使用的是android studio,请转到“项目”视图。你可以在app>;下找到google_maps_api(发布版)>;src>>;发布>>;res>>;价值观
您需要将签名配置添加到构建中。gradle(模块:app)文件
这就是我的文件所包含的内容-
另外,可以在多个设备上试用。我曾经因为设备上的一些应用程序设置而出现问题。在我重置所有应用程序设置后,它工作了
# 2 楼答案
您可以使用相同的Android API密钥进行调试和发布
包名可以相同,但由于您不能使用调试密钥库对发行版进行签名,证书指纹应该不同
使用keytool命令检查释放指纹是否正确: