lunes, 19 de agosto de 2013

HowTo use GoogleMaps API v2 on emulators

(Spanish version here)

Hi all, some months ago I have been exploring the Android programming platform and one of the most interesting faces is the google maps.   With Google Maps API v1 it was relatively easy to use maps in our apps (see http://www.sgoliver.net/?p=1949), however with the API v2 release many developers have found troubles to tests their applications in the platform emulators.

Fortunately, these problems often find their way to solve them thanks to the perseverance of users with the need to move the obstacle, that way I have been looking for the way to make Google Maps API v2 working on the emulators and with some info found in some places I got the way to make it working for me so knowing the needed of many people I want to share the steps that worked to me and hope they can help some one else.

Well, that's it, so let's describe the process:

1. Updates

First of all I had to update  Android SDK Tools  and Android SDK Platform-tools

From Android SDK Manager Update:

Tools:
    Android SDK Tools a 22.0.5
    Android SDK Platform-tools a 18.0.1

Android 4.1.2 (API 16)
    Install SDK Platform
    Samples for SDK (opcional)
    ARM EABI v7a System Image
    Intel x86 Atom System Image
    MIPS System Image
    Google APIs



2. google-play-services_lib library

2.1 Download the google-play-service from the following location (this is which worked to me, before I had installed the one with comes with the SDK but I think it is a newer version and maps doesn't work on it)


Download the google-play-services.zip by clicking on the Download button located in the upper right corner.



2.2 Uncompress google-play-services.zip wherever you want (<google-play-services-download-dir>)

2.3 On eclipse, import the google-play-service project (if it already exists, delete it to install this version)

    a. File - Import - Existing project into workspace
    b. In Select root directory: <google-play-services-download-dir>/libproject/google-play-services_lib
    c. In Projects, mark the project: google-play-services_lib
    d. Mark the checkbox: Copy projects into Workspace
    e. Finish



2.4 In google-play-services_lib project go to Properties - Android:

    a. In Project Build Target mark: Android 4.1.2
    b. In Library check the Is library is marked
    c. Make a clean and build to this recently imported project




3. Actions in the project using the maps

3.1 In the project go to Properties - Android

    a. In Project Build Target mark: Android 4.1.2
    b. In Library add the google-play-services_lib library



3.2 In the same Properties window, go to Java Build Path - Libraries

3.3 Check Android 4.1.2, Android Dependencies y Android Private Libraries are present.



3.4 Click Ok

3.5 In the project contextual menu go to Android Tools - Add Support Library

3.6 Accept the license

4. Emulator setup

4.1 Create a new emulator with the following configuration:

    In Android Virtual Device Manager:

    a. Device: 5.1” WVGA (480 x 800: mdpi)
    b. Target: Android 4.1.2 – API level 16
    c. CPU/ABI: ARM
    d. Leave the rest of properties to default



4.2 Start the emulator.



4.3 Download the following applications (from the  pc or laptop where the development environment is set up):

    a. com.google.android.gms-1.apk (http://uploaded.net/file/bnzl1si4)
    b. com.android.vending-1.apk (http://www.androidfilehost.com/?fid=9390135922294521859)

4.4 Start a terminal and install the applications in the emulator by using these commands (adb command is in <Android-sdk-home>/platform-tools)

    a. adb -e install <path-to>/com.google.android.gms-1.apk
    b. adb -e install <path-to>/com.android.vending-1.apk



4.5 We can see the installation of both applications were success, so now we can see that Google Play Services (com.google.android.gms-1.apk) and Google Play Store (com.android.vending-1.apk) are listed in the emulator  (Settings - Apps)



5. Run the application

5.1 At this point I suppose your project is well configured and have the properly permissions, to have a reference of how to create your Google maps API v2 see http://www.sgoliver.net/blog/?p=3244

5.2 Make a Clean and Build of the project.

5.3 Run your application as Android Application






Links:

Como usar GoogleMaps API v2 en emuladores

(English version here)

Hola amigos desde hace algunos meses he estado explorando la programación en la plataforma Android y uno de los aspectos más interesantes es el uso de los google maps.   Con el API v1 de google maps resultaba relativamente fácil utilizar mapas en nuestras aplicaciones (ver http://www.sgoliver.net/?p=1949), sin embargo con la salida del API v2 muchos desarrolladores nos hemos encontrado con problemas para testear las aplicaciones en los emuladores ofrecidos por la plataforma.

Afortunadamente, este tipo de problemas suelen encontrar su forma de solventarlos gracias a la perseverancia de usuarios con la necesidad de pasar el obstáculo, de ese modo yo mismo he estado buscando la forma de hacer funcionar el API v2 de google maps en los emuladores y con un poco de información encontrada por aqui y otra encontrada por allá logre hacer que me funcionen así que conociendo la necesidad de muchos deseo compartir los pasos que funcionaron para mi y espero que sean de ayuda para alguien más.

Bien, sin más preámbulos vamos a describir el proceso:

1. Actualizaciones


Lo primero que tuve que hacer fue actualizar el Android SDK Tools  y Android SDK Platform-tools.

desde el Android SDK Manager actualizar:

En Tools:
    Android SDK Tools a 22.0.5
    Android SDK Platform-tools a 18.0.1

En Android 4.1.2 (API 16)
    Instalar SDK Platform
    Samples for SDK (opcional)
    ARM EABI v7a System Image
    Intel x86 Atom System Image
    MIPS System Image
    Google APIs



2. Libreria google-play-services_lib



2.1 Descargar el google-play-service desde la siguiente ubicacion (con este es con el que me funciono, antes tenia instalado el que viene con el SDK pero creo que ese es una version mas reciente y los maps no funcionan con ese)


Descargar el archivo google-play-services.zip mediante el boton Download que hay en la esquina superior derecha




2.2 Descomprimir el contenido de google-play-services.zip en el directorio de su eleccion (<google-play-services-download-dir>)

2.3 En eclipse importar el proyecto google-play-service (Si ya existiera, eliminarlo para instalar esta version)

    a. File - Import - Existing project into workspace
    b. En Select root directory: <google-play-services-download-dir>/libproject/google-play-services_lib
    c. En Projects, seleccionar el proyecto: google-play-services_lib
    d. Marque la casilla: Copy projects into Workspace
    e. Finish



2.4 En el proyecto google-play-services_lib ir a propiedades - Android:

    a. en Project Build Target marque: Android 4.1.2
    b. en Library compruebe que Is library esta seleccionado
    c. haga un clean and build de este projecto que acaba de importar




3. Acciones en el Proyecto que usa los mapas



3.1 En el proyecto vaya a properties - Android

    a. en Project Build Target marque: Android 4.1.2
    b. en Library agregue la libreria google-play-services_lib



3.2 En la misma ventana de properties, vaya a Java Build Path - Libraries

3.3 Compruebe que se encuentran las librerias Android 4.1.2, Android Dependencies y Android Private Libraries



3.4 Acepte y cierre la ventana de propiedades

3.5 En el menu contextual del proyecto vaya a Android Tools - Add Support Library

3.6 Acepte la licencia

4. Configuracion del emulador

4.1 Crear un emulador con la siguiente configuracion:

    En el Android Virtual Device Manager:

    a. Device: 5.1” WVGA (480 x 800: mdpi)
    b. Target: Android 4.1.2 – API level 16
    c. CPU/ABI: ARM
    d. Deje el resto de valores por defecto



4.2 Inicie el emulador.



4.3 Descargue las siguientes aplicaciones (desde el pc o portatil que tiene el entorno de desarrollo):

    a. com.google.android.gms-1.apk (http://uploaded.net/file/bnzl1si4)
    b. com.android.vending-1.apk (http://www.androidfilehost.com/?fid=9390135922294521859)

4.4 Inicie un terminal e instale en el emulador las aplicaciones anteriores mediante estos comandos (el comando adb se encuentra en <Android-sdk_home>/platform-tools):

    a. adb -e install <path-to>/com.google.android.gms-1.apk
    b. adb -e install <path-to>/com.android.vending-1.apk



4.5 Se puede ver que la instalacion de los dos paquetes en el emulador ha sido exitosa, por lo tanto ahora si vemos las aplicaciones instaladas en el emulador podremos ver que tanto el Google Play Services (com.google.android.gms-1.apk) como el Google Play Store (com.android.vending-1.apk) estan instalados (Settings - Apps)




5. Ejecutar la aplicación


5.1 En este punto se supone que el proyecto esta bien configurado y tiene los permisos adecuados, para una referencia de como crear un proyecto Google maps API v2 visite http://www.sgoliver.net/blog/?p=3244

5.2 Haga un Clean and Build del proyecto.

5.3 Ejecute la aplicacion como Android Application






Enlaces:
http://stackoverflow.com/questions/15156301/google-play-services-out-of-date-requires-3025100-but-found-2012110/16891491#16891491
http://nemanjakovacevic.net/blog/english/2012/12/06/how-to-make-android-google-maps-v2-work-in-android-emulator/
http://langcongnghe.com/kien-thuc/android-running-google-maps-v2-on-android-emulator.html