Saturday, January 7, 2017

How to install google play store on android emulator (Android 7.1.1, API 25)

Recently I have been doing some stuff on android emulators and discovered that there is no google play store over there. Then I found some articles on how to install google play store on emulator (for example this website: www.flinkd.org) But most of the existing tutorials were for android 5, API 21 and when I tried to do them, links to gapps archives were broken and the archive format was slightly different than it is today on opengapps.org. So today I will give you new updated tutorial on how to install google play store on android emulator.

Let's start with a brief overview of what you might need and what are the possible ways of getting google play store on your android emulator.

Introduction


1. Android sdk

First, you need to have android sdk installed on your machine. If you don't know how to do it, check this video where I'm installing android sdk on Debian 8.

2. System image

Next, you need to choose a system image for your android emulator. There are different ones: Intel x86 Atom, ARM, Android Wear, Google APIs Intel x86 and so on.

In this tutorial I will use Google APIs Intel x86 system image. Why? Because it's the easiest way. When you install Google API image, you already have google services running in it, then you only need to push 1 package for google play store.

On the other hand, if you choose any other image, you will have no google services at all and will need to install them from scratch. I've tried embedding bare minimum of google packages (GoogleServicesFramework, GoogleLoginService, PrebuiltGmsCore, Phonesky) into Intel Atom image (API 24, 23, 22) and it seemed to work, but with constant errors like "unfortunately google services has stopped".

3. Android virtual device (AVD)

You will also need AVD installed. I've recorded another video tutorial for that, you can check it out. It's easy to install though and I will describe it below as well. So let's get started.

Tutorial


In this tutorial I'm using the following versions: Android 7.1.1, Google APIs Intel x86 Atom.

1. Install android 7.1.1 image


Launch android sdk manager:
./android-sdk/tools/android
and install Google APIs Intel x86 Atom system image:


2. Create AVD


From android sdk click on Tools > Manage AVDs -> Create. Then pick the right system image (Google APIs Intel x86 Atom), target (Android 7.1.1), enter name, skin, check use Host GPU, everything else can be as default.




3. Download GAPPS archive


Go to this website. Choose Platform (x86), Android version (7.1), Variant - pico. From that archive we will need to extract only one single file, so there is no reason of downloading any bigger format.



Extract files to a temporary directory:
unzip open_gapps-x86-7.1-pico-20170107.zip
Change directory to Core and extract another archive (you may need lzip installed):
cd Core
tar -xf vending-all.tar.lz
Copy Phonesky.apk to home directory, we will need it later:
cp vending-all/240-320-480/priv-app/Phonesky/Phonesky.apk ~/

If you want to try to embed google services on Intel x86 Atom image, then you would need at least 4 .apk files which are stored in: vending-all.tar.lz, gsflogin-all.tar.lz, gsfcore-all.tar.lz, gmscore-x86.tar.lz

4. Start avd


Start your virtual device from command line:
./android-sdk/tools/emulator @device7 -writable-system

5. Push play store to emulator


When avd is running, open a second terminal where we will be doing some hacking. Change directory:
cd ~/android-sdk/platfrom-tools

Enter to android's shell and get root:
./adb shell
su

Check where system directory is mounted to:
cat /proc/mounts|grep system

And then remount it with 'rw' permissions:
mount -o rw,remount /dev/block/vda /system

You may also check this directory '/system/priv-app' where you can see what services are installed. There we will push Phonesky.apk to enable play store.



Logout from android's shell by hitting Ctrl+D (twice).

Restart adb as root and push Phonesky.apk:
./adb root
~/adb push ~/Phonesky.apk /system/priv-app/

Restart avd:
./adb shell stop
./adb shell start

6. Google play store


At this point you should have google play store icon on your android emulator. Click on it and associate it with existing google account.



You can also watch detailed video on how to do all this stuff, step by step:

14 comments:

  1. Thanks a lot! you have been of great help.

    ReplyDelete
  2. Now it just says "Authentication required, you need to sign in blah blah" even if my account is linked. Any ideas? I'm trying to install it in API19, testing reasons. In a 540x960 res device.

    ReplyDelete
    Replies
    1. Same problem exist on API 25 too. also the Google Play services do not work afterwards.

      Delete
  3. I'm unable to extract that vending-all.tar.lz file with tar on osx and ubuntu, nor winrar or 7zip on windows.

    tar: Unrecognized archive format

    any suggestion?

    ReplyDelete
    Replies
    1. On Mac, Install lzip by "brew install lzip"(http://macappstore.org/lzip/), then use lzip to uncompress the file by "lzip -d vending-all.tar.lz". Then use "tar -xf vending-all.tar" to get the apk.

      Delete
    2. And on Windows, install https://github.com/mcmilk/7-Zip-zstd/releases - this is a version of 7-zip that includes lzip. The usual version doesn't!

      Delete
  4. I had to create a folder named "Phonesky" to the /system/priv-app/ location, and push the Phonesky.apk file there to get the Play Store working.

    ReplyDelete
  5. Thanks man! You save my day!

    ReplyDelete
  6. At you it is wrong! You must first create a folder /system/priv-app/Phonesky/ and ~/adb push ~/Phonesky.apk /system/priv-app/Phonesky/

    ReplyDelete
  7. 130|generic_x86:/ # cat /proc/mounts|grep system
    /dev/block/pci/pci0000:00/0000:00:03.0/by-name/system /system ext4 ro,seclabel,relatime,data=ordered 0 0
    generic_x86:/ # mount -o rw,remount /dev/block/pci/pci0000:00/0000:00:03.0/by-name/system /system
    '/dev/block/pci/pci0000:00/0000:00:03.0/by-name/system' is read-only

    ReplyDelete
  8. I tried so many documentation for day long (I wondered why so many people write so many half-tested blogs) and finally, I am succeeded after following your instructions. Thanks a lot.

    ReplyDelete