Home > Android > Installing the Google Play Store App (APK) on the Android Emulator

Installing the Google Play Store App (APK) on the Android Emulator

This has been tested on the Android Emulator that comes default installed with the Android SDK with Android Studio 2.2.3.

The Android OS version used was the latest Android 7.1.1 (Nougat) and the Google Play APK version was 10.0.84 from OpenGapps (although I think any latest versions of the APK should work).

The basic idea from this post was adapted from a StackOverflow post [1] that had good ideas, but I had to tweak them to get it to work for my case.

TL;DR: The basic idea is that you need to get the APK files put them in the right location of the system partition (after getting it to be writable). Then giving the APK’s the right permisions (I gave them all 777, i don’t know why, i just wanted it to work, but perhaps not so good for security. May be 755 will also work.). Then reboot, once rebooted shutdown the instance, delete the Emulator instance from the Android Virtual Device manager, and clone another image out of the one that was written to. (If you didn’t get that … all the details are below…)

Intro:

To get just the Google Play APK and it’s related services select the Pico version from the OpenGapps website. If you want other Google Apps also e.g. Gmail, Google Now, Google Music, Calendar, Youtube, etc you’ll have to select one of the other OpenGapps packages that has the apps you want.

Getting the APKs out of the OpenGapps ZIP (and TAR.LZ) archive

For this part you’ll need something that can open ZIP files and decompress the LZIP format. On Windows i used 7Zip and Lzip

I used the Windows batch script below found at the StackOverflow question cited[1] and created a batch file called unzip_gapps.bat. Make sure to change the line lzip -d GAPPS\Core\gmscore-x86_64.tar.lz to the file for which ever version of architecture you’re using, in my case it was x86 instead of x86_64

Put all the files (open_gapps-*.zip, 7z.exe, lzip.exe, unzip_gapps.bat) into a single directory and run the batch file.

@echo off
echo.
echo #################################
echo Extracting Gapps...
echo #################################
7z x -y open_gapps-*.zip -oGAPPS

echo Extracting Lzips...
lzip -d GAPPS\Core\gmscore-x86_64.tar.lz
lzip -d GAPPS\Core\gsfcore-all.tar.lz
lzip -d GAPPS\Core\gsflogin-all.tar.lz
lzip -d GAPPS\Core\vending-all.tar.lz

move GAPPS\Core\*.tar

echo.
echo #################################
echo Extracting tars...
echo #################################

7z e -y -r *.tar *.apk

echo.
echo #################################
echo Cleaning up...
echo #################################
rmdir /S /Q GAPPS
del *.tar

echo.
echo #################################
echo All done! Press any key to close.
echo #################################
pause>nul

The APK files should now be extracted and “automagically” appear in the directory.

Putting the APK’s in the right place on the Android device

NB: This needs some form of getting the /system partition (directory) to be writable, or to have root access in order to make the /System partition writable. I’ve seen some form of attempt at rooting the emulator here, in order to make the /system partition writable, but this didn’t do the trick for me.

Assuming that you have Android Studio, the SDK and an Emulator instance created with Android 7.1.1 (API 25), I had to start the emulator from the CLI with the directive writable-system

Windows:

 emulator.exe -avd <Emulator_Instance_Name> -writable-system 

Ubuntu:

./emulator -avd <Emulator_Instance_Name> -writable-system 

Now the APK’s need to be put into the /system/priv-app/ directory, inside directories, each with the specific name of the APK it contains. You’ll probably  need root privileges to write to the system/priv-app directory. I used adb root to grant me root access. For some reason I also needed to to adb remount  to make sure that the /system partition becomes writable (Not sure why, if i already asked the emulator to have a writable /system partition, but this had to be done).  For subsequent accesses you can also get into the shell using adb shell and then from there switch user to root with su root.

NB: You might already have the directories PrebuiltGmsCore, GoogleServicesFramework, GoogleLoginService. (Unlikely you’ll have Phonesky). But create whichever ones you need as seen below.

adb root
adb remount
adb shell

cd /system/priv-app

mkdir PrebuiltGmsCore

mkdir GoogleServicesFramework

mkdir GoogleLoginService

mkdir Phonesky

Exit the ADB shell. Now we need to Push the right APK files to the right directories:

 adb push <APK_file_path> /system/priv-app/<Destination_dir>/ 

e.g:

On Windows:


adb push C:\OpenGapps\PrebuiltGmsCore.apk /system/priv-app/PrebuiltGmsCore/

adb push C:\OpenGapps\GoogleServicesFramework.apk /system/priv-app/GoogleServicesFramework/

adb push C:\OpenGapps\GoogleLoginService.apk /system/priv-app/GoogleLoginService/

adb push C:\OpenGapps\Phonesky.apk /system/priv-app/Phonesky/

On Ubuntu:


./adb push ~/User1/OpenGapps/PrebuiltGmsCore.apk /system/priv-app/PrebuiltGmsCore/

./adb push ~/User1/OpenGapps/GoogleServicesFramework.apk /system/priv-app/GoogleServicesFramework/

./adb push ~/User1/OpenGapps/GoogleLoginService.apk /system/priv-app/GoogleLoginService/

./adb push ~/User1/OpenGapps/Phonesky.apk /system/priv-app/Phonesky/

Changing the Permissions of the APKs

Now you’ll need root access again to change the APK permissions. As mentioned earlier, i gave the permissions 777 to the files, but i’m not sure whether such high permissions are needed for all users, i think 755 might be more appropriate, but i haven’t tested this.


adb root

adb shell

chmod 777 /system/priv-app/PrebuiltGmsCore/PrebuiltGmsCore.apk

chmod 777 /system/priv-app/GoogleServicesFramework/GoogleServicesFramework.apk

chmod 777 /system/priv-app/GoogleLoginService/GoogleLoginService.apk

chmod 777 /system/priv-app/Phonesky/Phonesky.apk

At this point the APK’s might start installing themselves and you might get an error saying the Play Services have stopped or  com.google.Gmscore has stopped, or something close to that. Ignore it.

[Before April 2017, the rest of this guide was relevant, from April 2017, you don’t need to do the rest. Restarting the emulator should work.]

Restarting and Creating another Image 

(For Emulator versions, below v25, that is: Before April 2017)

Restart the Emulator and even now you’ll probably still be getting the Play Services have stopped or com.google.Gmscore has stopped or something close to that.

Now shutdown the emulator normally, using the power button long-press.

After it has shutdown, go to the Android Virtual Device (AVD) manager through Android Studio (Tools > Android > AVD Manager). Delete the Virtual Device Instance and create a new one (this sounds counter intuitive, but if you check the time-stamps of the system image where these devices are cloned from [ {android_version_home_dir}/sdk/system-images/{android-version-number}/system.img> ]  you’ll notice that the system was written to pretty recently). This is because  we had the writable-system directive when we were making the changes, thus the Play Store APK got installed to /system partition “permanently”, so any new AVD created for this particular version of Android, it will have the Google Play Store APK installed properly.

Create a new AVD from the modified system-image android version and you’ll see the Play Store App installed, ready and waiting on the home screen.

Sources:

[1]. http://stackoverflow.com/questions/34291902/android-studio-emulator-does-not-come-with-play-store-for-api-23

Advertisements
  1. Kavan Vadaliya
    February 12, 2017 at 10:23 AM

    After The install apk android emulator has black screen.Do not open after install

    • Irvin H.
      March 28, 2017 at 5:16 PM

      Not sure what could have gone wrong. Check the permissions of the apps and the folders that their in, maybe
      ¯\_(ツ)_/¯ … don’t have the time at the moment to do a deep dive into troubleshooting.

  2. March 14, 2017 at 7:32 PM

    Hi I require a GmsCore.apk for a new android tv box build. 6.0.1 ARM. Please advise if you are able to assist? Br hendi hendiv@gmail.com

  3. March 14, 2017 at 7:35 PM

    Hi I require a GmsCore.apk with play services 10.2.98 (434-146496160) for an android tv box. 6.o.1 ARM API23. Please advise if you are able to assist. Regards Hendi / hendiv@gmail.com

    • Irvin H.
      March 24, 2017 at 4:27 PM

      I suggest checking on OpenGapps or APKMirror, if you don’t find what you need there, i’m afraid i don’t have a quick solution for you.

  4. kevin pad
    March 25, 2017 at 11:58 PM

    This was an incredible tutorial. Except for at the end when after I was able to get Play Store successfully installed it told me to delete the device from AVD. Now Play Store isn’t there anymore and I have to do everything over again. Uh.

    • Irvin H.
      March 28, 2017 at 5:04 PM

      Well, i’m not exactly sure what happened in your scenario, but to my knowledge if the “system.img” file has been “written to” it means the change should be permanent, unless you update your emulator OS before restarting. Ensure that you have used the “-writable-system” directive, remounted, and also check the timestamp of the “system.img” file before deleting.

  5. robert
    March 28, 2017 at 8:19 AM

    good tutorial, i manage to execute all steps, up to giving permissions, but i followed the very last step (stop the emulator via long press power button, deleted, and created a new one), still no google play store 😦

    • Irvin H.
      March 28, 2017 at 5:08 PM

      Hmmm, i just answered a similar question by suggesting that you double-check the time-stamp the “system.img” file, to ensure that the /system partition got modified. Unless Google has changed something in their most recent versions of the emulator, i’m not entirely sure what’s going wrong. This worked for me just a few weeks ago [We’re in the last week of March 2017]

  6. Beej
    May 7, 2017 at 9:56 PM

    [this stack-o](http://stackoverflow.com/a/43375905/813599) was helpful regarding the system.img persistence issue…

    nutshell: save/restore your %userprofile%\.android\avd\Nexus_9_API_25.avd\system.img.qcow2

    which apparently represents the system.img mods we’re looking to persist (at least for the moment)

    other observations for the collective record…

    * i didn’t have to create a new virtual device per the last steps… i shutdown via device power button, then did a “wipe data” (via right mouse on the device entry in AVD Manager), restored the previous system.img.qcow2 file to that userprofile folder and upon restarting device, working Play Store was sitting in the app launcher (not on desktop)

    *i guess maybe don’t even do the wipe data and see if reboot is all that is necessary*

    * “Android 7.1.1 (with Google APIs)” target\ only needed Phonesky pushed, the other priv-apps were already present.

  7. Irvin H.
    May 9, 2017 at 1:59 PM

    Yes, I posted that Answer on StackOverflow after doing a bit of research, but i forgot to update my blog with the latest understanding / info of how the emulator actually persists stuff from April 2017 🙂 … i’ll update it soon. Thanks Beej for linking the StackOverflow post (http://stackoverflow.com/a/43375905/813599)

  1. May 9, 2017 at 12:25 AM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: