The Maps Sample from Google Play Services

After struggling for two days, I finally have the Google maps sample from the Google Play Services as an SDK extra build and run successfully. The sample is available if you install the Google Play Services in the extras section from the Android SDK Manager. It should be located at the path, C:\adt-bundle-windows\sdk\extras\google\google_play_services\samples\maps.

The following are the critical parts to successfully build and run the sample:

  • Google Play Services Library: how to import and set reference to
  • Android Support Library: how to add the support library
  • Google Play Services on the client side: probably requested to upgrade
  • Physical Android device required to test the app: Android Virtual Device is not supported

The procedures to build and run the sample are summarized as follows:

  1. Import the maps code
    • Import>Existing Android Code Into Workspace
    • C:\adt-bundle-windows\sdk\extras\google\google_play_services\samples\maps
  2. Import the Google Play Service Library code
    • Be careful! it’s the LIBRARY support code, not the service itself
    • Import>Existing Android Code Into Workspace
    • C:\adt-bundle-windows\sdk\extras\google\google_play_services\libproject\google-play-services_lib
  3. Reference the Google Play Service Library project
    • Be careful! This is the most critical step. Open the maps Project properties page, choose the Android item in the list and add a Library reference at the bottom edge.
    • DO NOT be confused with the Java Build Path Libraries or the Project References.
  4. Add Android Support Library
    • simply copy them as static libraries into your project or
    • right-click on the project and choose from the context menu, Android Tools>Add Support Library
  5. Assign your key for Google Map Android API v2
    • DO NOT be confused with the Google Map API v2, which is for browser apps.
    • You gotta turn on Google Map Android API v2 service and create new Android key in the Google API Console
    • Assign your key in the AndroidManifest.xml.
  6. Test the app in a physical devices
    • You may be requested to upgrade the Google Play Services on your device.
    • Be careful! Android Virtual Devices are not supported this time.

GoogleApiConsole GoogleMapAndroidApiKey AndroidLibrary GooglePlayServices

Android Support Library

The Android Support Library is offered as an SDK extra component that can be installed from the Android SDK Manager and located at the path sdk\extras, say C:\adt-bundle-windows\sdk\extras. It contains static libraries providing access to newer APIs on older platforms and various helper classes.

Each library is called v<api>, indicating the minimum API level that they require.

To use those libraries:

  • simply copy them as static libraries into your project or
  • right-click on the project and choose from the context menu, Android Tools>Add Support Library

The following are excerpts from the library README.txt:

*** V4 ***

v4/android-support-v4.jar contains:
Fragment API. New in API 11 (3.0 – Honeycomb). http://developer.android.com/reference/android/app/Fragment.html
Loader API. New in API 11 (3.0 – Honeycomb). http://developer.android.com/reference/android/app/LoaderManager.html
CursorAdapter / ResourceCursorAdapter / SimpleCursorAdapter. These are the API 11 versions.
MenuCompat allows calling MenuItem.setShowAsAction which only exists on API 11.

v4/src/ is the source code for the compatibility library
v4/samples/ provides a sample app using the library.
*** V13 ***

v13/android-support-v13.jar provides the same features as v4, plus:
FragmentPagerAdapter: Implementation of PagerAdapter that represents each page as a Fragment.

v13/src/ is the source code for the compatibility library, not including the v4 source
v13/samples/ provides a sample app using the library.

AndroidSupportLibrary

Change the API level of an Android Application Project under Source Control

There are many version/source control solutions for Eclipse. Microsoft Team Foundation Server 2010 (TFS) provides developers with the Microsoft Visual Studio Team Explorer Everywhere 2010 with SP1 as an Eclipse plug-in.

When you create a new Android application project, it is the first step that you select an API level as the project build target. You may afterwards change, for example, the API from Android 4.2 (level 17) to Google APIs 4.2 (level 17). You won’t make it because the project files are read-only if the Android project is under the control of TFS.

Check these two files out for edit before you change the API level or Android platform of an Android application project under source control:

  • AndroidManifest.xml
  • project.properties

EclipseTFS

Getting Started with Android Development

  • Install JDK (not JRE)
    • Set the system environment variable: JAVA_HOME
      say, C:\Program Files\Java\jdk1.7.0_09
    • Set the  system environment variable: CLASSPATH
      say, %JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar
    • Append java compiler path to the PATH system environment variable:
      say,  %JAVA_HOME%\bin
    • reboot and run javac.exe to verify if the installation is all right
  • Install ADT (Android Developer Tools)
    • Download, unzip the ADT Bundle for Windows and you are ready to go!
    • Start eclipse: say, C:\adt-bundle-windows\eclipse\eclipse.exe
  • Install all other versions of Android APIs
    • Start Android SDK Manager: Window>Android SDK Manager
    • Check all APIs and Extra to download and install
  • Set up an Android emulator (Andrord Virtual Device, AVD for short)
    • Windows>Android Virtual Device Manager>New
  • Create a new Android Application Project
    • The package name must be specified with your unique name: com.your unique name.helloandroid
    • Start the application: Debug as > Android Application
    • Inconsistent Naming! adt-bundle-{OS} has inconsistent SDK platform location for API 17
      The new adt-bundle-windows (and linix) have the API 17 SDK in platforms\android-4.2 instead of platforms\android-17. However, all the other SDK still download in the the named folders “android-“+apiLevel.
  • Import existing projects
    • File>Import>General>Existing Projects into Workspace
    • DO NOT choose: File>Import>Android>Existing Android Code into Workspace
  • When editting AndroidManifest.xml
    • If error appears: No grammar constraints detected for the document
    • Window>Preferences>XML>XML Files>Validations
      set No grammar specified to Ignore
  • Install Microsoft Visual Studio Team Explorer Everywhere 2010 with SP1
  • To regenerate the R class
    • Android Tools>Fix Project Properties
  • Eclipse hanged when starting
    • cd to <workspace>\.metadata\.plugins\org.eclipse.core.resources
    • remove the file .snap (or .markers in Indigo)
  • Android: failed to find style ‘mapviewstyle’ in current theme?
    • GO-TO : android-sdk/platforms/ <android-api-level> /data/res/values
    • In public.xml, check the mapViewStyle’s definition and id value.
    • In styles.xml, insert ‘mapViewStyle’ item element as shown below.

EclipseAndroid