问题
I'm using Google Maps API v2 for android and Google Places API, both have different api-keys to be added to manifest, but when i add both the keys, i got multiple-key error.
Is it possible to add two different keys for two different APIs, if not, then what is the possible work around?
<!-- Goolge Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD****************U6QybngOI" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyA******************KDaKCEJU" />
回答1:
You will want to use gradle with Placeholders.
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="${mapsKey}" />
And in your gradle add
android {
buildTypes {
debug {
manifestPlaceholders = [ mapsKey:"AIzaSyD****************U6QybngOI"]
}
}
}
回答2:
I solved the issue by using the same GEO API key for both Google Maps v2 and Google Places API, i-e the Geo api-key can be used for both places api and maps api as well.
<!-- Goolge Maps API Key -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyA******************KDaKCEJU" />
<!-- Google Places API Key -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyA******************KDaKCEJU" />
回答3:
To add release and debug keys change your gradle file. You first have to make the API keys in the Google Developer Console.
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId 'com.your.app'
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders = [ mapsKey:"AIzaxxxxxxxxxxxxxxxxxxxvcgdXNA"]
}
debug {
manifestPlaceholders = [ mapsKey:"AIzayyyyyyyyyyyyyyyyyyyyyyyC7NA"]
}
}
productFlavors {
}
}
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.google.android.gms:play-services:8.4.0' }
回答4:
You shouldn't use multiple key for this purpose. You just have to Enable Both services for the same API key, from the developers console.I think this answer will guide you through The process.
来源:https://stackoverflow.com/questions/33917437/multiple-api-keys-for-single-android-studio-project