- Consulting / Coaching
- Jeff’s Blog
After a couple failed attempts, I managed to successfully run com.example.mapdemo in an Android Virtual Device (AVD). It’s not tough, but required cobbling together instructions from a variety of sources.
The following instructions work for the ADT installed under Ubuntu, version linux-x86-20130522. I make no guarantee that these steps will work for you. It’s possible that some of the steps are extraneous.
Using the Android SDK Manager, install Google Play Services (v7).
Using the Android SDK Manager, install Google APIs (v3) (located under Android 4.2.2 (API 17)).
Using the Android Virtual Device Manager, create an AVD with a target of Android 4.2.2 – API Level 17. (I created mine with a 4.65″ 720p, not sure if that’s important.)
Start the AVD
Download two application package files (APKs):
Install the APKs using adb (located in the ADT directory ./sdk/platform-tools):
adb install com.android.vending-4.1.6.apk adb install com.google.android.gms-(3.1.36).apk
Restart the AVD
Copy ./sdk/extras/google/google_play_services/libproject/google-play-services_lib/ to your Android projects area.
Create a project for Google Play Services (projects needing to use Google Maps will need to depend on this):
Import->Android->Existing Android Code Into Workspace.
Navigate to ./sdk/extras/google/google_play_services/libproject and select google-play-services-lib.
Create a project for the map samples:
Import->Android-Existing Android Code Into Workspace.
Navigate to ./sdk/extras/google/google_play_services/samples and select the maps directory.
Create a Google Maps API key (note: these steps supposedly will not work for your production deployment):
Copy the SHA1 from your Android Debug keystore. Here’s the instructions I used under Ubuntu to display the contents of the keystore:
keytool -list -v -keystore ~/.android/debug.keystore
By default, the password for the keystore is android.
Go to https://code.google.com/apis/console and select API Access from the menu (to the left).
Click the button marked Create new Android Key….
Paste in your SHA1, append a semicolon, then append com.example.mapdemo
Click the Create button.
Copy the API key into the paste buffer (you will use it in the next step).
Configure the map sample project:
From the project’s build path settings, Add External JAR: ./sdk/extras/android/support/v4/android-support-v4.jar
Go to the Order and Export tab, and export android-support-v4.jar
Go to Properties->Android. In the Library section, add the google_play_services_lib project as a dependency. (You will need to open google-play-services_lib if it is not already.)
Edit AndroidManifest.xml to contain your API key: In MainActivityManifest.xml, ensure you have a meta-data element with something like the following:
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCawgR4hVSiAzHIg4wJMbg7jvNyt-KZNgs"/>
Substitute your API key for the android:value attribute. The meta-data element is a direct child of <application>.
Edit AndroidManifest.xml to contain appropriate permissions. For example (don’t forget to substitute your package name):
<permission android:name="com.langrsoft.plangrok.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="com.langrsoft.plangrok.permission.MAPS_RECEIVE" />
Here are some of the links I used to piece this together:
Please let me know if I missed any steps or if you discovered something else.