Get the API key. You must have at least one API key associated with your project. To get an API key: Visit the Google Cloud Platform Console. Click the project drop-down and select or create the project for which you want to add an API key. Click the menu button and select APIs & Services Credentials. On the Credentials page, click Create credentials API key. A key with this name can be used to authenticate to multiple Google Maps-based APIs on the Android platform, including the Google Maps Platform Premium Plan. For backwards compatibility, the API. Where do I find my Google Maps API key? Because of recent changes that Google did, you need your own Google Maps API key if you want to use Google Maps on you own website. But don't worry! It's very easy to get one and it's free - we'll show you how, step by step. Click on the following button to request your own API key (opens in new tab. Step 12: Now you need to enable all the highlighted APIs, that is Direction API, Distance Matrix API, Geocoding API, Geolocation API, Maps Embed API, Maps JavaScript API, Maps SDK for Android, Maps SDK for iOS, and Places API, to get a single Google API key for our platform. Aug 27, 2017 Go to the Google Developers Console. Click Create Project (If you don’t already have one, otherwise it defaults to an existing project). If you have an existing project, but want to create a new one, click the drop down, then the + button. Click ENABLE APIS AND SERVICES. Click Google Maps Android API. Then click enable.
OBSOLETED: this old question refers to obsoleted Google Maps v1 API. When using v2 API, you can use multiple certificate fingerprints in one Google API Console entry. API Key is no longer stored in Manifest nor code.
Is it possible to automatically detect, which certificate was used for signing APK? I’d like to have both debug and release Maps certificates in application and pass valid one to MapView constructor.
With such setup I will not make mistake while releasing application – I’m using debug certificate on emulator and my device, then sign with release one before sending app to Market.
I was thinking about detecting my particular device or whether debugger is connected but it is not perfect. Maybe some file marking need for debug certificate? Is there any better way?
There is a new way to determine is it a debug build or release one in SDK Tools, Revision 17. An excerpt from new features overview:
Builds now generate a class called BuildConfig containing a DEBUG constant that is automatically set according to your build type. You can check the (BuildConfig.DEBUG) constant in your code to run debug-only functions.
So now you can simply write something like this:
UPDATE: I’ve encountered bug in ADT: sometimes BuildConfig.DEBUG
is true
after exporting application package. Description is here: http://code.google.com/p/android/issues/detail?id=27940
Android generate aes gcm key. Had the same hassle with the API key. Here’s a full solution, based on the above link and example from Bijarni (which somehow didn’t work for me), I use now this method:
You have to find out your debug signature’s hashValue() once, just output sigs[i].hashCode().
Then, I didn’t want to dynamically add the MapView, but rather use the xml file. You cannot set the api key attribute in the code and use an xml layout, so I use this simple method (though copying the xml layout isn’t so beautiful):
In my MapActivity:
Much easier way to determine whether it is a debug build is by checking the debug flag on the application info than the signature hash.
Once debug build is found, either you can use different resource for showing map or create the mapview within the app and add to a layout.
I have worked around the horrendous mis-integration of the api keys into the build process and source control by making it a property stored in local.properties
. I had to add the following to build.xml
:
Now, of course I had to create mapview.xml.tpl
in my projects root (it can’t go to res/layout
because it will break the build process):
During pre-compilation, the template is copied to the right place and @[email protected] is replaced with the real key. Unfortunately I have not found a way to distinguish between debug and release builds in this phase, so to compile for release, I just add the release apiKey to the ant parameters:
This approach integrates well with SCM (I do not need to check in the keys) and acceptably with the build process.
If you’re still interested I just blogged about another way to do this. With a simple change to the Android build script, you can switch the Map API key as well as all other required release changes. What I like about this is that nothing debug-related goes into the release, and you can keep the XML layouts just the way they were before.
I think that creating an entry in the Google API’s console which includes both your release key and your debug key (both mapping to the same package) works great and is a much simpler way to not have to worry about whether you are debuging or compiling a release version.
The solution is outlined here
All answers here seem outdated, if you are using android studio then gradle is the way to go
Use different keys in your build.gradle
And in your AndroidManifest.xml
And if you want to save some passwords for debug and release differently then you should follow this
I’ve ended up with the special file on SD card – if present, use debug key; missing – use release one. And it works.
EDIT: see new accepted answer, it works better
I don’t know if this helps anyone but I have merged some of the other suggestions here to produce the following MapViewActivity.
In this example R.layout.map_dbg is only used if this is a debug build and the file exists (add this file to your .gitignore).
The advantages of this approach are :
The disadvantages of this approach are :
you need to remember to update map_dbg.xml every time map.xml is updated
I have setup a simple ant target that replaces the apikey with either a debug key or a release key. This is really simple and keeps the code free of unwanted logic.
In Map V2 Its easy to send seperate keys using Android Studio Gradle tool. I have implemented an easy way for that. please check the link here.
Tags: androidandroid, api