Click here to Skip to main content
15,881,862 members
Articles / Programming Languages / Java

How Can I Get Google Play to Work on Android Emulator in Android Studio and Visual Studio 2019

Rate me:
Please Sign up or sign in to vote.
4.83/5 (5 votes)
24 Apr 2020CPOL8 min read 38.1K   83   8   3
Simple tricks that may help you get your Emulators with Google Play Store up and running and shared between Android Studio and Visual Studio 2019
Having difficulty getting Google Play Store to work in the Android Emulators? This, article shows some simple tricks that may help you get your Emulators up and running and shared between Android Studio and Visual Studio 2019.

Shouldn't It Be Easy?

Have you been pulling your hair out because you can't get Google Play to work on the Android Emulator? Have you been asking yourself, "shouldn't it be easier to get such as simple thing to work so you can get back to writing code?" You see the options (for Google Play Store) in the GUI (at least on the Visual Studio side) and even some references to it in the AVD Manager. Yet, actually getting it to be active inside the Emulator is illusive. Well, pull your hair no more. This article will hopefully make this task a lot easier.

Background

Perhaps you have limited disk space and do not want to "waste" space by having two instances of the Android images installed for both Android Studio and Visual Studio. Or you just want to have one set of emulator images and Android SDK to manage and you want your emulators to support the Google Play Store but just can't get the GUI in the AVD Managers (whether in Visual Studio or Android Studio) to make it work. Either way, it is easier to get the Google Play Store to work when you only have to deal with one set of Emulators.

In this article, I will explain how to get both IDEs to use the same SDK. Then, I will explain how to get the Emulators to use the Google Play Store.

Get Both IDEs using the Same SDK

  1. Install Android Studio and the necessary SDKs you need, including the Emulator and Play store.
    1. I have found that Android Studio typically has the most up to date images so do this from the Android Studio side.
  2. Install Visual Studio, being sure to select the Android SDKs too.
  3. Once all the IDEs are installed, Start Android Studio and click on File > Settings > Appearance & Behavior > System Settings > Android SDK

    Image 1

    1. Note the path listed in the “Android SDK Location:” box:
  4. Start Visual Studio and click on Tools > Options > Xamarin > Android Settings

    Image 2

    1. Note the existing path for the Android SDK Location (so you can delete or rename this later)
    2. Change the path value for the Android SDK Location so it matches the path listed in Android Studio:
  5. Click OK to save the settings in Visual Studio. Then close and reopen Visual Studio for the changes to fully take effect.

That’s all you need to do to get both IDEs using the same SDK.

Get Google Play to Work in Your Emulators

1. Common Issues Worth Mentioning

1. Not Having The Latest Updates

  1. I can’t stress this enough. Have the latest versions of your images. Ensure each image SDK has the latest available. I recommend updating from Android Studio vs. Visual Studio as (assuming you are using a single SDK location (see above)) Android Studio seems to acquire the newer releases sooner. I can’t tell you how many times the Google Play package has broken on me only to be fixed by updating to the latest versions of the Platform Images, the latest Emulator, and Build tools.
    1. You can update the SDK in Android Studio by clicking File > Settings > Appearance & Behavior > System Settings > Android SDK.

      Image 3

    2. Don’t forget to select the check box in the lower right “Show Package Details” to see all the packages available. Often, the Google Play enabled packages are not even selected by default. Be sure and select them.

2. You Can’t Enable Google Play In The GUI

  1. First, I think it is worth mentioning that there are many discussions and forum threads on this subject. Many suggest various ways of solving the problem but very few address what I consider to be the actual root cause of this issue: Bugs within the AVD Manager apps on both the Android Studio side as well as the Visual Studio side that prevent the configuration files from being created correctly.
  2. What? They both have issues? Yes. Let me explain. As of the time of this writing (4/23/2020), if you modify or create any AVD in Android Studio, you will NOT receive the option to enable the Google Play Store, even if you select an Android Image from the SDK that states that has “Google Play.”

    Image 4

    1. In fact, if you attempt to edit an existing “built in” Device (one that ships with the installation of Android Studio AVD) that shows it has Google Play and save that modification, it will lose its ability to use Google Play.
    2. Visual Studio produces the same result. In the modification window of the Visual Studio AVD, there are two check boxes, one says “Google APIs” and the other “Google Play Store.” Both of these checkboxes should correlate to settings in the configuration of that AVD. Don’t waste your time clicking them though, they are useless checkboxes as their values do not actually get written to the configuration file of the AVD. You may or may not be able to check both of these anyway (Truthfully, I think it has to do with the hardware profiles of the AVD found at %localappdata%\Android\Sdk\tools\lib\devices.xml but I am not sure how to add a profile to this file because I can't find documentation on proper structure and options). Image 5

2. So How Do You Get This to Work Already?

  1. Short answer: Modify the config files yourself.
  2. Long answer: You may have already figured out that you need to modify the config files yourself due to the bugs with the AVD Managers of both IDEs. You may not know where the files are. The following instructions will help you.
    1. First, stop trying to use the GUI to modify your AVDs, it just breaks your AVD.
    2. Navigate to the following directory (or wherever you have your AVDs saved):
      1. C:\Users\YOUR_USERNAME\.android\avd
    3. Shutdown the AVD if it is running. Do a COMPLETE shutdown by powering it off from the emulator power button (just like if you powered down a real device).
    4. In this directory, you will see all of your AVDs listed, a directory and file for each one. Before you start mucking around, make a quick copy of the one you want to modify. It might take a bit, some of the image files are quite large.
    5. Next, enter the directory of the AVD you want to modify and find the file called:
      1. config.ini
      2. Open it in a text editor
    6. Find the line in the file starting with “PlayStore.enabled”.
    7. Make sure the entire line says “PlayStore.enabled = true
    8. Now, find the line that starts with “image.sysdir.1
      1. Which may have the incorrect value of “system-images\android-29\google_apis\x86” or “system-images\android-29\default\x86
      2. This is supposed to be the path to the image directory that the emulator will use. It seems the AVD Managers cannot add a "playstore" path. You need to make sure the path points to a valid image path and that path must be a path to an image that has the Play Store enabled. At the time of this writing, the path on my system to Platform Image Q is:
        1. system-images\android-29\google_apis_playstore\x86

          1. Use a relative path in this file as above, however, for your information only, the full path is: C:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk\system-images\android-29\google_apis_playstore\x86
          2. Note the addition to the path “_playstore”, this is key, but you’re not done yet.
          3. The full line should look something like this:
          4. image.sysdir.1=system-images\android-29\google_apis_playstore\x86_64\
      3. Update all paths in the file that point to this same directory to include the “_playstore” portion of the directory name within the file.
    9. So the AVD shows up correctly in the list of AVDs in the AVD Manager add or modify the following line items:
      1. tag.display=Google Play
        tag.id=google_apis_playstore
    10. Save the file and close it.
    11. Now open the file “hardware-qemu.ini” in a text editor.
    12. Again, you will find and modify or add the value “PlayStore.enabled = true”.
    13. Next, update the paths to the SDK images so that they all point to the PlayStore version:
      1. kernel.path
        			disk.ramdisk.path
        			disk.systemPartition.initPath
        			disk.vendorPartition.initPath
      2. Use Full paths in this file, don’t use relative paths here. The paths should generally match the paths you used above when modifying the config.ini file although not relative.
        1. The full lines should look something like this:
          kernel.path = C:\Users\YOUR_USERNAME\AppData\Local\Android\Sdk\
          system-images\android-29\google_apis_playstore\x86\kernel-ranchu-64
          disk.ramdisk.path = C:\Users\YOUR_USERNAME\AppData\Local\Android\
          Sdk\system-images\android-29\google_apis_playstore\x86\ramdisk.img
          disk.systemPartition.initPath = C:\Users\YOUR_USERNAME\AppData\Local\
          Android\Sdk\system-images\android-29\google_apis_playstore\x86\system.img
          disk.vendorPartition.initPath = C:\Users\YOUR_USERNAME\AppData\Local\
          Android\Sdk\system-images\android-29\google_apis_playstore\x86
      3. Another side point here is that you may even find that the existing paths are faulty having double backslashes perhaps. A result of the buggy AVD Manager used to write them. Go ahead and fix any faulty paths so they point to the correct directory or file.
      4. Save and close the file.

Points of Interest

By the way, there are only three files the AVD must have in its directory to actually start:

  1. config.ini
  2. sdcard.img
  3. userdata.img

If you would like to reset your AVD completely, you can delete all other files and directories from the AVD directory, leaving just those three files.

If you do this, modify just the config.ini file according to the instructions above then restart your AVD and the hardware-qemu.ini file will get written correctly when the AVD is started.

You can download some example ini files: exampleINIFiles.zip Image 6.

History

  • 24th April, 2020: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThis helped, thanks! Pin
Jonathan Harmon12-Nov-22 6:39
Jonathan Harmon12-Nov-22 6:39 
QuestionWhere the file "hardware-qemu.ini" is located ?? Pin
DS Tester 700119-Apr-22 19:44
DS Tester 700119-Apr-22 19:44 
PraiseIntelligent solution Pin
Ali Moussawi29-Apr-20 5:11
Ali Moussawi29-Apr-20 5:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.