FORUMS

Market on Emulator

11 posts
Thanks Meter: 17
 
By M4rketSqueezer, Junior Member on 1st July 2011, 01:57 PM
Post Reply Email Thread
Hi everyone! It's my first post. Did the "Noob video" kind of emerge from a frustration with new users?

Purpose
I want to run the Android Market on Android 2.3 inside the emulator, since I don't want to register a Google account on my phone. I donwload the apps there and transfer them to my phone.

Situation
I successfully set up an AVD with 1.6 and 2.3 where the Market seems to run flawlessly. However, it's not really deterministic what conditions lead to a running Market [1]. I want to be able to make all modifications of the SDK images and APKs myself in order to run the market. I consulted several guides already [2]:
  • Varun's How to: Install Android market on Emulator <hxxp://blog.varunkumar.me/2010/11/how-to-install-android-market-in-google.html>
  • Anything simple: How to use Android Market on Android Emulator 2.2 <hxxp://anythingsimple.blogspot.com/2010/09/how-to-use-android-market-on-android.html>
  • Tech-Recipes: How Do I Install the Android Market on Android SDK <hxxp://w#w.tech-recipes.com/rx/10004/accessing-android-market-from-android-sdk/>
  • CareAce: How to fix "protected" Android Market app <hxxp://w#w.careace.net/2010/06/16/how-to-fix-protected-android-market-app/>
All files I used are provided.

What I did
I followed the guide by Varun and it worked quite well, but it really worked only after I changed ro.secure=1 and ro.allow.mock.location=0 in default.prop (located in ramdisk.img).
  1. Create a new AVD. Config.ini:
    Code:
    hw.lcd.density=160
    hw.gps=yes
    hw.camera=yes
    hw.ramSize=256
    sdcard.size=256M
  2. Edit build.prop (see attachment, original values are commented with ###)
  3. Install Vending.apk and GoogleServicesFramework.apk
  4. Delete SdkSetup.apk
  5. ro.secure=1 and ro.allow.mock.location=0
When using GSF provided by Varun, the Market runs fine. When I use the GSF from my phone, it doesn't work. So, my two questions:
  1. What exactly does a running market depend on? (Only fingerprint and gsf?)
  2. Is the GSF by Varun the original or a patched variant?
  3. How could my version of the GSF be modified to work?


Attachments
CRC32 values are in parantheses.
  • com.android.vending.apk (6502c750)
    Original Market v2.3.6 as downloaded by the Market Updater
  • Vending_Adi.apk (a51aa807)
    Above patched on byte basis [3] (no re-assembling, modification directly in classes.dex for minimal deviation from original).
    Installed on my working AVD.
  • GoogleServicesFramework_htc.apk (3f770666)
    Version 2.2.1
    I pulled this file from my HTC Desire Z with Android 2.2.1
  • GoogleServicesFramework_varun.apk (6b3ea386)
    Version 2.2
    Available from Varun's guide


[1] A non-running Market only shows TerraTime on the home screen and games like PapiWall and PapiStep.
[2] Sorry for the obfuscation of the links. It's because this is my first post.
[3] I will explain every modification in detail, if asked for.
Attached Thumbnails
Click image for larger version

Name:	Working_Market.jpg
Views:	715
Size:	84.0 KB
ID:	642817  
Attached Files
File Type: apk com.android.vending.apk - [Click for QR Code] (1.83 MB, 1018 views)
File Type: apk Vending_Adi.apk - [Click for QR Code] (1.24 MB, 812 views)
File Type: apk GoogleServicesFramework_htc.apk - [Click for QR Code] (1.34 MB, 902 views)
File Type: txt build.prop.txt - [Click for QR Code] (1.9 KB, 1349 views)
11th October 2011, 06:49 PM |#2  
Junior Member
Thanks Meter: 1
 
More
I've been trying to get the market working on the emulator "properly" for days.

Can you find protected apps such as g-mon or dr droid?

If yes PLEASE can you post a detailed howto?

It could be that they fixed it with the latest packages, judging from comments on some blog entries on the subject, so don't update your SDK before making a backup!

Thanks in advance,
- MF
27th October 2011, 10:43 PM |#3  
Member
Thanks Meter: 2
 
More
How did u change "ro.secure=1 and ro.allow.mock.location=0" ?
17th November 2011, 03:45 PM |#4  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by MFighter

Can you find protected apps such as g-mon or dr droid?

If yes PLEASE can you post a detailed howto?

Edit build.prop in "system.img" before running emulator.

1) copy "%SDK%\platforms\android-10\images\system.img" "%userprofile%\.android\avd\%AVD%.avd\system.i mg"
2) open this file with binary file editor,
3) search "# begin build properties" or "23 20 62 65 67 69 6E 20 62 75 69 6C 64 20 70 72",
4) rewrite build.prop's content with real device's.
20th December 2011, 11:36 AM |#5  
Junior Member
Thanks Meter: 0
 
More
Quote:
Originally Posted by mrawekul

Edit build.prop in "system.img" before running emulator.

1) copy "%SDK%\platforms\android-10\images\system.img" "%userprofile%\.android\avd\%AVD%.avd\system.i mg"
2) open this file with binary file editor,
3) search "# begin build properties" or "23 20 62 65 67 69 6E 20 62 75 69 6C 64 20 70 72",
4) rewrite build.prop's content with real device's.

Don't suppose you would be willing to share your system.img file. I understand most of this but I tried to edit the system.img with no success. And there is no ramdisk.img in the avd folder. Can you help me out? I've tried everything. All I want to do is be able to download apps from the market so I can install on my tablet which is a Pandigital Planet and some of the apps don't show up on the market.
23rd December 2011, 12:53 AM |#6  
Junior Member
Thanks Meter: 3
 
More
Lightbulb Persisting system.img and trying to make Android Market application to work
Actually, there is a way to persist system partition.

Built-in command line help shows that there is an optional persistent system-qemu.img. If it worked, all the hoops below would be not necessary.

If it try to create system-qemu.img in .avd directory as a copy of system.img from one the platforms in the SDK, emulator fails with an error
Code:
ko:Missing initial system image path!
. My guess is that emulator was deliberately crippled to not support persistent /system partition out of the box. If someone has a method to make system-qemu.img to actually work, please post.
I quickly looked through the emulator sources, the patch to enable system-qemu.img would be a pretty easy task for someone who has built android emulator from sources at least once. Any volunteers?

Read on for a hack to get system-qemu.img functionality.

When emulator starts, it creates a copy of system.img in %temp%/AndroidEmulator with some random name like TMP9323.tmp. If you do
Code:
adb -e remount
to mount /system as rw, you will get the writable system, but with an empty free space. Everything you do to /system is saved into this .tmp file.

The next trick is to start emulator instance with more virtual sectors than there are actually are in the stock system.img. You do that by starting emulator with the aptly named emulator command like so
Code:
emulator @AvdName -partition-size 256
If look later at free space with df, you will get something like this
Code:
adb -e shell df
Filesystem             Size   Used   Free   Blksize
/dev                   252M    32K   252M   4096
/mnt/asec              252M     0K   252M   4096
/mnt/obb               252M     0K   252M   4096
/system                248M    96M   151M   4096
/data                  248M    34M   213M   4096
/cache                  64M     1M    62M   4096
/mnt/sdcard            252M     1K   252M   512
/mnt/secure/asec       252M     1K   252M   512
Note that you now have some free space in /system.

Later you do
Code:
adb remount
from your host shell. This is essentially the same as running
Code:
#mount -o remount,rw /dev/block/mtdblock0 /system
from emulator shell.
Now you get the fully writable /system filesystem. You can copy with
Code:
adb push
any files you like into the /system and they will be successfully written.

After you are happy with your new /system, from
Code:
adb -e shell
you sync filesystems and make system read-only:
Code:
#sync
#mount -o remount,ro /dev/block/mtdblock0 /system
After that you can hot copy the .tmp to some other place and close the emulator with an [x] button from the window title bar. I do not use snapshots, so closing emulator is akin to removing the battery from a real device.

And using snapshots to get a "persistent" /system is impossible without rebooting. Currently it is not possible to shutdown via emulated power button (F7). The emulator manual says just to close the emulator window. If you do that with snapshots enabled, you will get into the state you were when you closed the window. Also it is not possible to reboot, as there are no documented way to reset the virtual processor. The reboot command does not work. It just hangs the emulator-arm.exe with 100% use of the CPU core it happens to run on. That is another observation for emulator was deliberately crippled or not developed to a point when resetting the virtual processor is possible.

Later you put your .tmp file into your .avd directory with a name of system.img. And when you start your emulator (even from AVD Manager GUI) you will get your new /system.

If you later need to make some modification to /system, you need to go through all the steps again.

When starting emulator with a new /system for the first time, I recommend to check "Wipe user data" to recreate the file and directory structure in the /data partition, especially if you pushed new .apk files into /system/app or pushed some other system wide components like .jar (framework) or .so (library) files.

Wiping a /data partition can be a lengthy process because it leads to recreation of dalvik-cache, the most CPU demanding process. In most cases, you can avoid the /data wipe. But if you push Google Apps to a pristine AVD, you should do a wipe so that Google initialization program with "Touch Droid to begin" kicks in. It is a first step screen the user sees at least on a real, Google "enhanced" device based on Android 2.3.

You can even observe how userdata-qemu.img file gets bigger as dalvik-cache and other parts of /data get populated. You may even use the
Code:
top
command to see the processes on the emulated device.

If you are running emulator from the command line you can add -wipe-data option to wipe the /data partition.

Optionally you can remove cache.img from .avd directory to clear the cache. cache.img will be recreated from scratch in this case.

After all these manipulations, the only way to launch AVD would be from command line as -partition-size 256 must be specified every time, otherwise you will get a kernel panic when mounting the /system partition.

The GUI option "Ideal size of system partition" is actually ignored. Its value is not copied into hardware-qemu.ini from config.ini, but stays at the size of initial system.img. Just another observation that emulator was deliberately crippled.

If emulator hangs with textual (not graphical) "A N D R O I D" on its screen, it is likely that the new system.img is corrupted and/or the partition size of 256MB has not been specified for not stock system.img. You can verify this by launching AVD from the command line with -show-kernel option to get all the kernel output in real time. You will likely find a kernel panic there.

If emulator hangs with a graphical ANDROID animation (aka boot loop), you can use
Code:
adb -e logcat
tool to look for any errors in the start up process. Examples below.

But that was an easy part. Now we need to install Vending.apk and its dependencies.

As my goal is Android 2.3.3, as it is a close to current majority of real devices as it can be. I tried to work with the version of Google Apps for CyanogenMod. I own an HTC Desire with CyanogneMod 7.1-nightly. I downloaded the initial gapps-gb-20110828-signed.zip from the link in CM wiki. This .zip, when flashed through recovery works without any issues on CM. Also I pulled from HTC Desire an updated Android Market .apk. Also I generated a demo app which shows a text edit and a button, but does nothing just to check that .apks can be installed both as system and 3rd party apps.

Here is what I tried.

0. Started with a Google API (API Level 10) emulator images. Pushed unpacked gapps. Everything worked: initial Google account registration, Talk, Maps, Latitude, Navigaton, Places, News and Weather (widget + app), Search (including widget). But not Market. There were no icon for it. Fail.

1. Started with Android 2.3.3 (API Level 10) emulator images. Pushed unpacked gapps. Got a boot loop with an exception in logcat related to contacts migration/upgrade. Strange, Google API 10 image may have something that plain image does not have. Fail.

2. Started with Android 2.3.3 (API Level 10) emulator images. Pushed upgraded Vending.apk to /system/app. No Market icon after a reset. Even with data wipe. Fail.

3. Started with a Google API (API Level 10) emulator images. Tried to install through adb the latest Vending.apk as a third-party app. adb install failed with "INSTALL_FAILED_ALREADY_EXISTS". Fail.

4. Started with a Google API (API Level 10) emulator images. Deleted /system/app/SdkSetup.apk. Tried to install latest Vending.apk with adb. Same result as in 3. Fail.

5. Started with a Google API (API Level 10) emulator images. Deleted /system/app/SdkSetup.apk. Pushed latest Vending.apk to /system/app. After reboot no icon. Also pushed own app, it got the icon. Vending.apk got no entry in /data/dalvik-cache, but demo app got it. Something prevents the Vending.apk to be recognized as a valid app. Fail.

6. Same as 5, but pushed not as Vending.apk, but as foobar.apk. Same result. No icon after reboot, no entry in dalvik-cache. Fail.

Spent the last 4 hours for figuring out the method for /system persistence and Vending.apk experiments.

Some possible reasons for Market Application to not show up in dalvik cache and no icon in launcher application list:
1. Some metadata in .apk prevents it from being processed. SDK level?
2. Crypto keys mismatch. Firmware signing keys != .apk signing keys.
3. Apk contents conflict with something existing in the firmware. (INSTALL_FAILED_ALREADY_EXISTS).
4. Permission issues.
5. System image configuration variables like ro.secure and ro.allow.mock.location.

The next step for me would be to read 3 books:
1. Learning Android.
2. Application Security for the Android Platform
3. Android Forensics: Investigation, Analysis and Mobile Security for Google Android

As I plan to fork or contribute to pffmod (http://forum.xda-developers.com/showthread.php?t=996726), I had to read them anyway.

If someone has a working method to put recent Android Market into Android 2.3.3 (API level 10) or Google API (API level 10) emulator images, please post.
The Following 3 Users Say Thank You to geckoneer For This Useful Post: [ View ] Gift geckoneer Ad-Free
5th February 2012, 11:14 AM |#7  
Junior Member
Flag KL
Thanks Meter: 1
 
More
nice information M4rketSqueezer and geckoneer! may be try to change the property ro.config.nocheckin=yes? i have 2.1 emulator with market now..same method as M4rketSqueezer
13th March 2012, 10:20 PM |#8  
Jimieo's Avatar
Senior Member
Flag New London, CT
Thanks Meter: 83
 
More
I don't have my device yet and want to take advantage of what few apps are still 49 cents.

I've been trying to follow this method today and when I get to the pulling build.prop part I get a cmd error saying adb is not recognized as an internal or external command.

I'm not sure what I did wrong :\
20th March 2012, 12:19 AM |#9  
Junior Member
Flag Giza
Thanks Meter: 0
 
More
Post
I've download the image referenced in this article at techdroid.kbeanie.com/2011/01/android-market-on-emulator-22.html. This post is merely for 2.2, but I managed to extract their googleservicesframework.apk and vending.apk from inside the image(using adb pull while the emulator is running). I then created a normal 2.3 AVD, started it from the command line with -partition-size 100, pushed the pak files I just extracted from 2.2, and followed geckoneer's hints for getting the system image that contained the pushed apk files. Now having that image with the market apk files, I ran that image inside the emulator and got the market running successfully. Once you start the market for the first time it'll run you through the google account registration wizard. Once you complete with an account, you'll have the market running and I tried searching and downloading applications from it. I've attached the two apk files for convenience.
Two points are noteworthy here: I had to change /system/build.prop inside the system image to one of the real supported models in google market at support.google.com/googleplay/bin/answer.py?hl=en&answer=1727131. I extracted the file from my mobile which was Samsung galaxy mini GT-S5570. I had to replace some of the values(especially those related to the model and manufacturer) in build.prop inside the emulator with those from my mobile.
The second point is that, after I exit the market(with several back-button presses till I get to the home screen) or restart the emulator. It seems the market isn't working properly. By working properly I mean that when I search for something in the search box, it just reports the number of matched results it found for my search(like saying 543 matches or so), without actually displaying the result. So far the only fix I managed to find to this was by restarting the emulator from the command line with -wipe-data; this repeats the google account registration process when I try to run the market again, and it's once again running effectively just after the registration, but it'll get crippled soon if I exit it or restart the emulator. This seems like an annoyance, but other than that the image works fine.
Attached Files
File Type: apk googleservicesframework.apk - [Click for QR Code] (813.2 KB, 159 views)
File Type: apk vending.apk - [Click for QR Code] (995.6 KB, 154 views)
Post Reply Subscribe to Thread

Tags
hack, market

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes