Developing a Simple Google Map Application in Android [debug/release modes] (Android 4.0, Google Play Service, Google Maps Android API v2)

Today I’m going to post about an android application which uses Google Maps. I’m going to use Google Maps Android API v2(since Google Maps Android API v1 is deprecated) and it is not easy to use as Google Maps Android API v1. The steps which you have to follow is mentioned below.

Remember, please don’t waste time try running this application with an Emulator. I have seen many people tried run these types of application with an Emulator, but most of the time it has failed.

My Development Environment

Samsung S2(GT-I9100) with Android version 4.0.3(which was upgraded from Android 2.0+). Also this is quite important, I had the latest Google Play Service installed in it.

If you have this kind of environment I guaranteed that the application will run smoothly.

Because of Google Maps Android API v2, is strongly connected with Google Play Service library, you need to download it first. You can easily do it using the Android SDK Manager.


Once it is downloaded you can find a folder called google-play-services_lib. It will be available in your Android-SDK -> Extras -> Google -> google_play_services -> libproject folder.
Ex: C:\Program Files (x86)\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib

Import it as an android project to your Eclipse environment/your workspace.


Once the project is imported, we can start implementing our Android Map Application.

First you have to create an Android Project, in my case I set the target Platform into Android 4.0 & API Level 14. My project name was Rakimap and the package name was com.rakimap. The Activity name was MainActivity, which is added by default.

Then what you have to do is you have to reference the google-play-services_lib project which you have imported earlier.


Then it comes to the most easiest but trickiest part of the project, In order to you the Google Map API Services you have to obtain a key. Whether you are in the debug environment or release environment you have to use a key in order to use the facilities of this API. So here’s how you do it.

Debug Environment

You need to use the debug.keystore file, if you are using Eclipse IDE you will be able to find it under Users -> <current-user-name> -> .android folder. Ex: C:\Users\rawilk\.android

The open the command prompt and navigate to you jdk-version\bin folder (Ex: C:\Program Files (x86)\Java\jdk1.5.0\bin), where you can find the keytool.exe. In there you have to execute this command.

keytool.exe -list -v -keystore “<file path>\debug.keystore” -alias androiddebugkey -storepass android -keypass android

debug key

Once it is executed it will response back with set of lines.

debug key-sha

There you can find two types of certificate fingerprints and you have to copy the SHA1 value for later usage.

Then you should visit this link Google Api Console. As I prefer the new Google Cloud API Console, you will be seen a page like this once you logged-in. You have to go to APIs section which is under APIs & auth. In there if the Google Maps Android API v2 status is OFF, turn it ON.


Once it’s done move to the Credentials section. In there click the Create new Key button.


Once you click it a popup dialog will be opened. There you press the button named as Android key.


Once you click it you will be seen another pop-up screen which asks the SHA1 value which you have copied earlier. Once you put it, then enter a semi-colon and then enter the name of the package as it is in the project. (This is the package which contains the Activity which will be used for displaying the Google Map later in this). In my case it was com.rakimap.


Once you click the Create button you will be able to get the API key. Copy it and keep it somewhere because we are going to use it later in the project that you have created.

Finally here we go with the blank activity which you created earlier. Let’s make it really simple. Here’s how the MainActivity class would be.

package com.rakimap;

import android.os.Bundle;

public class MainActivity extends Activity {

	static final LatLng COLOMBO = new LatLng(6.927, 79.861);
	private GoogleMap map;

	protected void onCreate(Bundle savedInstanceState) {

		map = ((MapFragment) getFragmentManager().findFragmentById(

		Marker markerColombo = map.addMarker(new MarkerOptions().position(

		// Move the camera to Colombo area with the zoom level of 20.
		map.moveCamera(CameraUpdateFactory.newLatLngZoom(COLOMBO, 20));

		// Animating the camera while zooming.
		map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);


Make the layout file like this. In my case it was the activity_main.xml.

<RelativeLayout xmlns:android=""
    tools:context=".MainActivity" >

        class="" />


Here’s how the AndroidManifest.xml is going to be.

You have to put the obtained Google API Key inside a meta-data tag block, as well as set some additional user permissions as below mentioned.  Also remember to use the correct package name where necessary.
Ex: com.rakimap.permission.MAPS_RECEIVE

<manifest xmlns:android=""
    android:versionName="1.0" >

        android:targetSdkVersion="14" />

        android:protectionLevel="signature" />

        android:required="true" />

    <uses-permission android:name="com.rakimap.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

        android:theme="@style/AppTheme" >
            android:label="@string/app_name" >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            android:value="AIzaSyAb8-sm4w3X9SXAHFCDhFdDZkayPfLjgiw" />
            android:value="@integer/google_play_services_version" />



Once this is done, try building the project to rectify any compile time errors. If there are no errors, plug-in your android device(I hope you have the per-requisites knowledge of how to handle an android device in development environment) and try deploying it.

You will be seen this if All Is Well.


Release Environment

When it comes to release the application as an APK, obtaining of the Google API Key will same, but you need to create a separate key-store for this.(you won’t automatically get a key-store like debug.keystore).

Open command prompt and navigate to the location of keytool.exe. Once you there you have to execute the below command in order to create the private key which you will be used in exporting the android application.

keytool.exe -genkey -v -keystore “<path of the release key to be stored>\<name of the file>” -alias <release key alias name> -keyalg RSA -keysize 2048 -validity 10000

Ex: keytool.exe -genkey -v -keystore “C:\RakiMap\raki-release.keystore” -alias raki-release-key -keyalg    RSA -keysize 2048 -validity 10000


Once you execute this, you will be asked a series of questions which you need to be answered. Answering for some of the questions are not needed. Refer the below shown image to get an idea.


If the key generation is successful(please locate where it resides), you can follow the same steps to obtain a new Google API Key for release mode. Before that you need to get the SHA1 value for the newly generated key. To do that execute the below command.

keytool.exe -list -v -keystore “<path of the release key to be stored>\<name of the file>”

Ex: keytool.exe -list -v -keystore “C:\RakiMap\raki-release.keystore”


So once you obtain the new Google API Key for release mode, you have to modify the AndroidManifest.xml file.

Then you can rebuild the program and you are ready to export the application for releasing. I hope you know the initial steps of exporting the android application when it comes to the Keystore selection dialog, you have to set the newly generated keystore file and use the same password which you used when building the key.


Once you press next you will be seen a dialog like this. There you have to select the alias name which you have given when you building the key. Use the same password as well.


After that it is pretty straightforward, you have to set a path to generate the APK file. Once the APK file is generated try installing it in the device. If All Is Well you will be seen this again.