How to install Google Maps v2 in Android Emulator and use it in Intellij Idea?

Integrating Google Maps (or any map service) is always a nice feature for our applications, but it seems to be “complicated” for integrating Google Maps because Google Maps is not officially supported in emulator because lacking of Google Play Service. That forces us to use a real device during developing app. For me, not nice. So in this post, I would like to show step by step how I configure my emulator so that a Google Maps app can be installed on there. To make such an emulator, we have to use a set of correct settings/files. If not, it won’t work. So you have to set all settings like mine. My emulator targets on Android 4.2.2 – API Level 17.

AVD Android 4.2.2

1. Install Google Play Service packages into emulator.

1.1 Start your emulator. Disconnect any other Android device (such as your smartphone) from computer.
1.2 Download these two files

com.android.vending-19032013.apk : http://www.mediafire.com/download.php?7jfar2v1bzx6v59
com.google.android.gms-19032013.apk : http://www.mediafire.com/download.php?4o9fz413uavlblf

1.3 Open command console, go to \platform-tools , it can be

C:\Users\ServusKevin\android-sdks\platform-tools or
C:\Users\ServusKevin\AppData\Local\Android\sdk\platform-tools

Install two files above with command

adb install \com.android.vending-19032013.apk
adb install \com.google.android.gms-19032013.apk

If installation is successful, you’ll see message Success at the end

Vending Gms Installation Successful

If installation failed, see hints at the end of this post to solve your errors.

2. Download and configure the Google Play services SDK.

The Google Maps Android API is distributed as part of this SDK. The current version of Google Play service is r6. But don’t install it from SDK Manager. Our installed Google Play packages before is compatible only with r5. Therefore download Google Play services SDK r5 from this following link http://www.mediafire.com/download.php?l6n6waw2w92cuk3 extract it to folder \extras\google . If you already installed r6, uninstall it. If not, you’ll get error “Google Play services out of date. Requires 3027100 but found 3025110”.

3.Obtain an API key.

You will need to register a project in the Google APIs Console https://code.google.com/apis/console, and get a signing certificate for your app.
3.1. Open command console, go to \bin , it can be

C:\Program Files\Java\jdk1.6.0_37\bin or
C:\Program Files (x86)\Java\jdk1.6.0_39\bin

Enter this command “keytool -v -list -keystore “. Please note that the  can be located at following folders

C:\Users\ServusKevin\.android\debug.keystore or
C:\Users\ServusKevin\android-sdks\.android\debug.keystore

It depends on your IDE, default is in \.android\debug.keystore but in my case, is in \.android\debug.keystore. After running the command you’ll get SHA1 fingerprint

SHA1 Fingerprint

write down your SHA1 Fingerprint C7:04:A8:75:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx
3.2. Go to https://code.google.com/apis/console, create your project if necessary (find more info here Google Api Console register).  On the left of panel, go to API Access –> Create new Android key

Create new Android key

The syntax should be SHA1_Fingerprint;Package_Name_Of_Your_App . After creating a new key, an API key will be created, write down this new API key, you’ll need it for your Android app.

Android API Key

3.3. On the panel go Google API Console, go to Services –> Activate Google Maps Android API v2 (don’t be confused with Google Maps API v2)

Activate Google Maps Android  API v2

4. Create Android app to show Google Maps with Intellij Idea

4.1 Create an Android project. Please note that the package name is the name was used before at step 3.2.
4.2 Make reference to google-play-services, in Intellij IDEA, File –> Project Structure –> Modules –> Add –> Import Module

Intellij IDEA import module

Browse to \extras\google\google-play-services\libproject\google-play-services_lib –> OK –> Import module from external model (Eclipse) –> Next –> Next –> Finish. You’ll get one module more at the end.

Google Play Service Module

In Project Structure panel, click to choose your app module, go to Dependencies –> click on + –> Module Dependency –> Choose google-play-services_lib

Add Google Play Service lib dependency

In Project Structure panel, click to choose your app module, go to Dependencies –> click on + –> Jar or directories –> Browse to \extras\google\google-play-services\libproject\google-play-services_lib\libs –> Choose google-play-services.jar

At the end, you’ll get 2 dependencies in your app module

Google Play Service dependency

5. Specify settings in the Application Manifest.

5.1. Get the API Key and set it AndroidManifest.xml. Add the following element as a child of the element, by inserting it just before the closing tag :

 <meta-data  android:name="com.google.android.maps.v2.API_KEY"
                    android:value="YOUR_API_KEY"/>

substituting your API key for YOUR_API_KEY.  This element sets the key com.google.android.maps.v2.API_KEY to the value YOUR_API_KEY and makes the API key visible to any MapFragment in your application.

5.2. Specify more permissions in the Application Manifest like following

<permission
		android:name="com.hintdesk.Google_Maps_example.permission.MAPS_RECEIVE"
		android:protectionLevel="signature"></permission>
<uses-permission
		android:name="com.hintdesk.Google_Maps_example.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission
		android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission
		android:name="android.permission.INTERNET"/>
<uses-permission
		android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
		android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission
		android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
		android:glEsVersion="0x00020000"
		android:required="true"/>

android.permission.INTERNET : Used by the API to download map tiles from Google Maps servers.
android.permission.ACCESS_NETWORK_STATE : Allows the API to check the connection status in order to determine whether data can be downloaded.
com.google.android.providers.gsf.permission.READ_GSERVICES : Allows the API to access Google web-based services.
android.permission.WRITE_EXTERNAL_STORAGE : Allows the API to cache map tile data in the device’s external storage area.
android.permission.ACCESS_COARSE_LOCATION : Allows the API to use WiFi or mobile cell data (or both) to determine the device’s location.
android.permission.ACCESS_FINE_LOCATION : Allows the API to use the Global Positioning System (GPS) to determine the device’s location to within a very small area.
 : Because version 2 of the Google Maps Android API requires OpenGL ES version 2. This notifies external services of the requirement. In particular, it has the effect of preventing Google Play Store from displaying your app on devices that don’t support OpenGL ES version 2.

6. Add Google Maps fragment to activity

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
	android:id="@+id/map"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	class="com.google.android.gms.maps.MapFragment"/>

7. Show a Google Maps Marker on component

public class MainActivity extends Activity {

    private GoogleMap googleMap;
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        googleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
        googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        final LatLng CIU = new LatLng(1.926, 73.400);
        Marker ciu = googleMap.addMarker(new MarkerOptions()
                .position(CIU).title("My dreamed island"));
    }
}

Google Maps on emulator

So now you can show Google Map on your Android emulator. However maybe you will get some errors during setting up.

8. Common errors

8.1 [INSTALL_FAILED_SHARED_USER_INCOMPATIBLE]

To solve this error, follow these steps
– Keep your emulator on.
– In Intellij IDEA, menu Tools –> Android –> Monitor (DDMS included).

Intellij IDEA DDMS

– In Android Debug Monitor, go to File Explorer –> /data/system/packages.xml –> Save it to your computer (from button “Pull a file from the device” with disk symbol)
– Search to “com.google.uid.shared” and delete all nodes below it (my case :  )
– Save it back to emulator through button “Push a file onto the device” with phone symbol.
– On emulator, click on turn off button (Basic Controls section) to reboot the device.

8.2 [INSTALL_FAILED_ALREADY_EXISTS]

To solve this error, just uninstall the existing packages with command
– adb uninstall com.android.vending
– adb uninstall com.google.android.gms

8.3 You get a white blank Google Maps with 2 zoom buttons

Create a completely new AVD and follow the steps above again, be sure that you regenerate SHA1 key with your current debug.keystore. If you install new Android SDK, then you’ll need new SHA1 key and so new API Key. Remember when AVD was successfully created, don’t change its target to Google Api. It makes your AVD damaged and Google Maps won’t work anymore.

9. Updates

9.1 Updates 12.03.2015

– Pre installed AVD Image with Google Maps

http://www.mediafire.com/download/u1dkem56otfieaq/Nexus_One_API_17.avd.zip

Please note that you have to generate your SHA1 key and API key in AndroidManifest.xml so that Google Maps can be loaded

– Source code https://bitbucket.org/hintdesk/android-how-to-install-google-maps-in-android-emulator-and-use

15 thoughts on “How to install Google Maps v2 in Android Emulator and use it in Intellij Idea?”

  1. @Scarabaea: The picture with Module Dependencies is for the paragraph above. For jar file is the next paragraph.

    In Project Structure panel, click to choose your app module, go to Dependencies –> click on + –> Jar or directories –> Browse to \extras\google\google-play-services\libproject\google-play-services_lib\libs –> Choose google-play-services.jar

  2. I installed the apks and managed to compile, the maps shows on my actual device, but it doesn’t work on my emulator.

    I used the apks you provided.

    Plz help 🙁

  3. @Gabriel: For emulator you have to install Google Play Services. Check Step 1 in the post to see how you can do that. The post is already written step by step. Just follow it.

  4. Thanks for your great work , i’ve got a problem in using adb ,
    i followed all the steps , but i’ve got an error ” Failure [INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES] ”
    i dont know what should i do , Thanks 🙂

  5. @Ahmed: It seems to be that you already have a another version of com.android.vending or com.google.android.gms installed in your AVD. Uninstall other version and try again.

  6. I am attempting to install Google Play Services for the emulator; however, I keep getting access denied. I’m not sure, how to deal with this problem :/

  7. @Carissa Samaroo: I can’t help you because your error description is not detailed enough so that I understand what’s going on.

  8. i followed all the steps , but i’ve got an error ” Failure [INSTALL_FAILED_INVALID_APK] ”
    iPlease tell me the solution , Thanks

  9. @Muhammad Asim Irshad : Check your steps again I think there’s a conflict between version of your Android OS and supported version of Google Play Services.

  10. Hello Admin,
    did you check the steps again? and did you find where is the error?

    best regards and a million thanks

Leave a Reply

Your email address will not be published. Required fields are marked *