在Android虚拟机中安装GooglePlayServices

原文地址:http://piotrbuda.eu/2012/05/installing-google-play-on-android-emulator.html

Installing Google Play on Android Emulator

The problem

I wanted to install Google Play on emulator. Problem is no guide on the net could tell me precisely how to do this. I’m not sure why, it seemed that they worked with old Android Market (pre version 3 era) or at least people shown some screenshots of that but I couldn’t make it work at home.

The difference was that I tried to install Google Play on an Ice Cream Sandwitch emulator (API level 15) and it always failed.

First attempts

I first found this site. I tried setting up everything from there but I just couldn’t make it work. Possible because their Vending.apk couldn’t start, I have no clue. Then I found this site and I somehow managed to install Vending.apk on emulator using this guide, but I couldn’t reproduce that.

One of the problems with those guides (which made me spend a lot of time on something useless) was that both these guides made me delete two files from AVD: cache.img and userdata-qemu.img. Why? Apparently when you wanted to restart emulator, these files were responsible for reinitialization of emulator to it’s starting state (like full wipe/factory reset). I tried and tried and I always ended up without my changes.

New Hope

After that I found that there is a snapshot option in AVD configuration window so I just checked it and finally I was able to see last state of emulator. Maybe it’s not perfect – it works like hibernation on your laptop – but it works and after a whole day of fight it was enough.

I then though why do I install some obsolete Vending.apk and GoogleServicesFramework.apk? Why can’t I have a new one there? So I connected my phone and pulled those apks from it. Of course it didn’t work, but I was not sure why. But I remembered something – CyanogenMod has Google apps packed in a zip (UPDATE: CyanogenMod does no longer host Google Apps, but you can find them here! So I downloaded their package and extracted everything I needed – Vending.apk and GoogleServicesFramework.apk. But it was not enough.

So I had an AVD set up with snapshots enabled and I proceeded to installing my new apks – full script will be posted at the end.

1. You have to remount system partition in read-write mode.
2. Then it's necessary to allow writing to /system/app directory
3. After that is done just push apks to /system/app/. (notice the dot at the end) 
4. Just for the sake of other guides I also remove /system/app/SdkSetup* (both apk and odex)

Voila! Google Play is installed on emulator! But it still doesn’t work. In order for it to start working, you need an account – Google account. This step also cost me some time. My AVD was based on Android 4.0.3, not the Google APIs one. So I changed it and… still nothing.

Apparently in recent releases Google decided to decouple their account provider from the OS so they have a separate apk that allows configuration of Google accounts – it’s called GoogleLoginService.apk. Pushing this to emulator solved all the problems – you don’t even need Google APIs (you can set up against Android 4.0.3 option). Now when you enter Play Store you get prompted for an account and it works!

Conclusion

After two days of trying I finally was able to launch and browse Google Play Store on an Android emulator with Ice Cream Sandwitch. Phew.

Command I use to start my emulator

1
emulator -avd am -partition-size 200 -no-audio -no-boot-anim

Full script (assumes you have created and started your AVD)

1
2
3
4
5
6
adb shell mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system
adb shell chmod 777 /system/app
adb push GoogleLoginService.apk /system/app/.
adb push GoogleServicesFramework.apk /system/app/.
adb push Vending.apk /system/app/.
adb shell rm /system/app/SdkSetup*

That script will work as long as you run it from a dir in which you have all the necessary apks. Of course you have to have your PATH environment variable set correctly (so that all those commands are actually accessible) but I suppose you know that already.

Settings of the AVD

Working Google Play Store


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
关于Google Play services的各个分支介绍(MX5一定要安装XXXXXX-448分支) 要想使用google playgoogle map等google应用,就必须安装Google Play Service,但Google Play Service有太多分支了,最近终于搞明白各个分支代表什么。 版本号最后三位(2104405-XYZ)分别表示Android版本,cpu的arm系列,屏幕密度(DPI)。 下面是具体分支介绍: Notes / What's New Uploader's notes: To figure out the right version of Google Play services for your Android device, go to Settings -> Apps -> Google Play services, and look at the last 3 numbers in the parentheses. You'll see something like -XYZ where: 1.第一位X * X defines Android version: 0 for Android =5.0 // 4和7表示Android5.0及以上 8 for Android TV // 8表示Android电视应用 2.第二位Y * Y defines CPU architecture: 1 for armeabi 3 for armeabi-v7a // 32位版本 4 for arm64-v8a // 64位v8版本,MX5必须是这个 7 for x86 // x86主要是对intel cpu来说的 3.第三位Z * Z defines DPI: 0 for universal 2 for 160 4 for 240 6 for 320 8 for 480 // MX5选这个就行了 Notes: It seems that -7YZ builds became -4YZ with Google Play services 6.5. If you were on -7YZ before, you should now install -4YZ. Looks like -8YZ builds are for Android TV. Examples: -014 for Android <5.0 armeabi CPU 240 DPI device -438 for Android 5.0+ armeabi-v7a CPU 480 DPI device -876 for Android TV x86 CPU 320 DPI device 国内用户可以直接从以下镜像网站下载最新到Google Play Service http://www.apkmirror.com/apk/google-inc/google-play-services/ 目前最新版本是Google Play services 7.8.93 MX5用户可以安装以下分支: Google Play services 7.8.93 (2104405-448) http://www.apkmirror.com/apk/google-inc/google-play-services/google-play-services-7-8-93-2104405-448-android-apk-download/ 另外,安装后好需要禁止系统自带【应用心】自动安装更新,可以设置面流量更新,但不要设置“静默安装更新包”,否则新版本发布后会自动更新成应用心的最新版本,而最新版本的后三位可能不是你想要的分支,这时候就会导致弹出提示架构不符等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值