【发布时间】:2016-01-08 10:24:16
【问题描述】:
所以我在我的应用程序中使用了 google maps api。我添加了活动并将 api 密钥放入 google_maps_api.xml(debug) 中,然后创建了一个不同的 api 密钥并将其放入 /release 下的 google_maps_api.xml 中,我必须去文件资源管理器才能找到它。如果我通过 android studio 中的绿色播放按钮启动应用程序,则地图加载得很好。但是当我在构建下生成 apk 时,地图不会加载。我相信这是由于 api 不起作用。我担心的一个问题是编辑 google_maps_api(release) 的唯一方法是在资源管理器中找到它。非常感谢所有帮助!
这是清单:
<?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'
}
【问题讨论】:
-
您必须更改活动的构建变体才能查看特定于发布的资源。一般在左下角
-
你能发布你的应用程序的 build.gradle 文件吗?
-
好的,刚刚添加了build.gradle。
-
您在构建 APK 时使用什么密钥库?您是否使用相同的密钥库来生成第二个 Maps API 密钥?
-
我通过点击开发者控制台的链接添加了 api 密钥,并输入了 SHA-1 指纹和包名称。
标签: java google-maps android-studio