Multiple API Keys for Single Studio Studio Project

I use the Google Maps API v2 for Android and the Google Places API, both have different api keys to add to the manifest, but when I add both keys, I get an error with multiple keys.

Is it possible to add two different keys for two different APIs, if not, what is the possible work?

<!-- 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
source share
4 answers

I solved the problem using the same GEO API key for Google Maps v2 and the Google Places API, i.e. Geo api-key can be used for both api and api maps.

 <!-- 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" /> 
+1
source

You want to use gradle with Placeholders .

 <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="${mapsKey}" /> 

And in gradle add

 android { buildTypes { debug { manifestPlaceholders = [ mapsKey:"AIzaSyD****************U6QybngOI"] } } } 
+2
source

To add release and debug keys, modify the gradle file. First you need 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 '}

0
source

You should not use multiple keys for this. You just need to enable both services for the same API key from the developer console. I think this answer will help you in this process.

0
source

Source: https://habr.com/ru/post/1270666/


All Articles