17

When integrating a Google Plus login button in an Android app, I'm observing some differences in how the button appears on an actual device and in the emulator. I am aware of the fact that the Google Plus services APKs are not installed in the emulator, but this can be worked around by pulling the APKs from a device and installing them into the emulator using APK.

My current "implementation" simply includes the login button in a layout, by referring to the button with the following XML code:

<com.google.android.gms.common.SignInButton
    android:id="@+id/sign_in_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

When I test my app on the device, the button appears all red and shiny, according to the guidelines mentioned here https://developers.google.com/+/mobile/android/sign-in . But when running on the emulator, it's just a normal button (grey background with black text) saying "Sign in with Google".

Any idea why the results are different? I've made sure I'm running the same API level, and the resource does seem to get pulled in correctly also on the emulator since it shows the actual login button (but with a different look).

Update: Found a clue in logcat; the message "Sign in button not found, using placeholder instead." pretty much explains why I'm seeing the grey dull button on the emulator. Still need to figure out why; could be the "copy google plus apk's from device" hack isn't working properly.

2
  • is the Android API level the same on device and emulator? Commented Apr 14, 2013 at 15:59
  • Yes, as I wrote in my question. Commented Apr 14, 2013 at 16:15

4 Answers 4

54

Google Play services works on the 4.2.2 versions of the Android Emulator and is officially supported as described in the Android documentation: Setup Google Play Services.

Update

You now can use the Intel/x86 images (HAXM-compatible) for API 19 and newer and for ARM, Google Play Services is available on most images.

Setting up the image

To get the right image for your virtual device manager:

  • Open the Android SDK Manager
  • Open the group Android 4.2.2 (API 17)
  • Check Google APIs
  • Check ARM EABI v7a System Image

enter image description here

To create the Virtual Device:

  • Open the Android Virtual Device Manager
  • Create a New device
  • Enter an AVD name
  • Set the target to Google APIs (Google Inc.) - API Level 17
  • Save your Virtual device and start it...

Note CPU/ABI will be fixed as ARM

enter image description here

Now you should be able to use the Google Play Services in the emulator. Of note, you need to set your target appropriately in your Android project to the Google APIs in order for Google Play Services to work.

7
  • 3
    Are there any plans to make this work with the Intel Atom x86 image? The ARM emulator is pretty much unusable.
    – jophde
    Commented Nov 11, 2013 at 20:42
  • I agree with @jophde that the ARM emulator is dog slow, take 4 to 5 times as long to launch and do stuff. Commented Jan 14, 2014 at 17:45
  • i m not able to run map in emulator, can u plz help me for that
    – Richa
    Commented Jul 17, 2014 at 11:33
  • @Richa please ask another question tagging google-maps - stackoverflow.com/questions/tagged/google-maps
    – class
    Commented Aug 13, 2014 at 17:44
  • @class Can you explain what you mean by "Of note, you need to set your target appropriately in your Android project to the Google APIs in order for Google Play Services to work."? Commented Oct 25, 2015 at 18:00
4

I tried most combinations of running the emulator, but with and without the Google APIs, which means I tested with both x86 and arm modes. I found no way of making the apk's pulled from my Galaxy Nexus phone to run correctly on the emulator.

Guessing this is somewhat related to getting the Play Store up and running, I decided to try that as well to see if I had more luck. I did not; could not get that working either. The Play Store icons appear and can be launched, but it immediately closes itself.

What did work however was to download and install the apks at the bottom of the page here:

http://umut.tekguc.info/en/content/google-android-map-v2-step-step

After installing the vending and gms packages, the login button appeared in it's full beauty under the emulator. Since I haven't actually implemented the actual login functionality yet, I can not be sure that it will actually work, but at least the button now looks identical in my app on my device and in the emulator.

You also need to download the Google Play Services software (look under "Extras" in the Android SDK manager), and install the library google-play-services_lib in your project (File-Import-Android-Existing Android Code Into Workspace, and then browse to for instance /opt/adt-bundle-linux/sdk/extras/google/google_play_services/libproject and select google-play-services_lib).

Another interesting tidbit is that this will only work on the "pure" Android emulator setups, not with the "Google API" setups. It seems the latter have some parts of those apps installed in the emulator already (not visibly and not working), and I haven't managed to remove the existing versions to install the custom apk files that worked as described above. I tested adb remove, adb install, adb install -r, and even removing the directories from /data which also failed. It's looking very much like Google is trying to make this difficult.

I'm disappointed Google is making this so hard; Google may have some weird licensing reasons for keeping this stuff out of the emulator, but if they really want people to use their services in their Android apps they need to make these services available in the emulator. Forcing people to always develop on a device (with otherwise excellent emulators available) or making people jump through hoops (lots of googling, installing unofficial/hacked versions of the apks etc) is just evil.

Final update before accepting my answer; although the correct button with the correct styling is now showing in the emulator, I am still not able to get the "pick account" dialog to appear in the emulator. When/if I do I will share the proper solution here.

4
  • And I thought their motto was "don't be evil"! :) Commented Oct 21, 2013 at 18:07
  • I get the message: "Failure [INSTALL_FAILED_SHARED_USER_INCOMPATIBLE]" when I try to install the APKs. Commented Oct 21, 2013 at 18:30
  • As you said, installing Google Play Services with adb is only possible with a "pure" Android emulator system image. But with such a system image you can't add a Google account to the phone! And if you check the Google Play Services compatibility with GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity) it tells you that "Google Play Services are not supported by your device" :(
    – FlorianT
    Commented Oct 29, 2017 at 12:50
  • Seems like it is possible to install Google Services and Google Play on clear AVD system image (without G API), but not possible to make them work.
    – B-GangsteR
    Commented Oct 31, 2018 at 15:25
0

Check the ldpi, mdpi, hdpi, etc... folders for a different button graphic. Your emulator is almost certainly a different DPI than your device.

2
  • I think the emulator and phone have the same settings; I'm using the Galaxy Nexus emulator setting and testing with a Galaxy Nexus phone. Regardless, there is no graphics at all, just a plain old button, on the emulator, while on the phone there is the "g+" logo and localized text. Commented Apr 14, 2013 at 16:17
  • There are different styles applied based on API level, screen resolution and DPI too. Did you look through those?
    – Bill Mote
    Commented Apr 14, 2013 at 16:31
0

Android image with google API implementedi have noticed that from API 21 there are ARM and x86 images with Google APIs implemented perhaps if you have no problem emulating using android 5 it will works without extracting the APKs

1
  • Does Google play services work? I haven't tried using the play store in the emulator but selecting the image with the API implemented allowed me to make use of the play services perhaps you can try to install the play store using the apk file while using that Google api image?
    – Fuseteam
    Commented Feb 17, 2016 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.