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
- Install Android Studio and the necessary SDKs you need, including the Emulator and Play store.
- I have found that Android Studio typically has the most up to date images so do this from the Android Studio side.
- Install Visual Studio, being sure to select the Android SDKs too.
- Once all the IDEs are installed, Start Android Studio and click on File > Settings > Appearance & Behavior > System Settings > Android SDK
- Note the path listed in the “Android SDK Location:” box:
- Start Visual Studio and click on Tools > Options > Xamarin > Android Settings
- Note the existing path for the Android SDK Location (so you can delete or rename this later)
- Change the path value for the Android SDK Location so it matches the path listed in Android Studio:
- 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
- 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.
- You can update the SDK in Android Studio by clicking File > Settings > Appearance & Behavior > System Settings > Android SDK.
- 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
- 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.
- 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.”
- 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.
- 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).
2. So How Do You Get This to Work Already?
- Short answer: Modify the config files yourself.
- 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.
- First, stop trying to use the GUI to modify your AVDs, it just breaks your AVD.
- Navigate to the following directory (or wherever you have your AVDs saved):
- C:\Users\YOUR_USERNAME\.android\avd
- 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).
- 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.
- Next, enter the directory of the AVD you want to modify and find the file called:
- “config.ini”
- Open it in a text editor
- Find the line in the file starting with “
PlayStore.enabled
”. - Make sure the entire line says “
PlayStore.enabled = true
” - Now, find the line that starts with “
image.sysdir.1
”
- Which may have the incorrect value of “system-images\android-29\google_apis\x86” or “system-images\android-29\default\x86”
- 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:
-
system-images\android-29\google_apis_playstore\x86
- 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
- Note the addition to the path “_playstore”, this is key, but you’re not done yet.
- The full line should look something like this:
-
image.sysdir.1=system-images\android-29\google_apis_playstore\x86_64\
- Update all paths in the file that point to this same directory to include the “_playstore” portion of the directory name within the file.
- So the AVD shows up correctly in the list of AVDs in the AVD Manager add or modify the following line items:
-
tag.display=Google Play
tag.id=google_apis_playstore
- Save the file and close it.
- Now open the file “hardware-qemu.ini” in a text editor.
- Again, you will find and modify or add the value “
PlayStore.enabled = true
”. - Next, update the paths to the SDK images so that they all point to the PlayStore version:
-
kernel.path
disk.ramdisk.path
disk.systemPartition.initPath
disk.vendorPartition.initPath
- 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.
- 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
- 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.
- 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:
- config.ini
- sdcard.img
- 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 .
History
- 24th April, 2020: Initial version