Blog Archives

Updating the Hostfile for testing on the android

For a new test I had to update the hostfile on my droid to point to a new environment, this task turned out be to be tougher than it should be – considering a droid is basically a computer.

The hostfile is protected and in order to be able to modify it you need to be able to “root” the phone  (android version of iPhone’s jailbrake, basically break into the phone to override defaults).  This was easier said than done, I found many references to z4root.  Many of the links didn’t work, or went to a site siezed by the US government, or my local AV software would prevent the download due to it triggering virus alerts.  When I finally got the file, I found the that the OS that came installed default on my phone (Huawei U8500) had been fixed and I couldn’t use z4root.

So in the end I ended up using the Emulator that is installed with the android SDK (note you do not need eclipse for this, I don’t even have eclipse installed).  I ran the AVD Manager, and created a virtual device that matched the specs of my test Android Huawei U8500 (I called the device huawei_u8500).  Then I ran the emulator (launching it command line) with that single device

emulator -wipe-dataavd huawei_u8500

-wipe-date has the emulator start with a clean image.

Once it was running (takes a few minutes to launch, knowing the hot keys to naviagate helps, since I the emulator lacks a back button.

Android Emulator: Keyboard Commands (http://developer.android.com/guide/developing/tools/emulator.html)

Then came updating the host file, one thing you need to do is remount the device image as writable, then pull the file, update it, and copy it back.  Fortunately that is actually easy compared to everything else.

remount the device image as writable

adb remount

Pull the host file from the device

adb pull /system/etc/hosts c:\Android\hosts

You can put the file anywhere and call it anything you want, I called it “hosts” and put it in my android directory

Next open the file in your favorite test editor (I use notepad++, but notepad is fine).  Add in the host file entries you need, for me this was the change:

127.0.0.1     localhost  (this was the original entry)
10.16.1.11  www.newsite.com  (what I added for my test)

Copy the edited hosts file back to your “device”

adb push c:\Android\hosts /system/etc

Now you are done and ready to test, every time in the emulator you go to “www,newsite.com” it will now be directed to 10.16.1.11.

 

 

Running a test script

Apparently monkeyrunner is brain dead if you run it like this:

monkeyrunner test.py

It will fail with the error:

Can’t open specified script file
Usage: monkeyrunner [options] SCRIPT_FILE

-s      MonkeyServer IP Address.
-p      MonkeyServer TCP Port.
-v      MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF)

This is due to monkeyrunner looking for the script where monkeyrunner is located not where you running it from. So instead of looking for my test.py file in C:0001101\Android> it looks for it where monkeyrunner is in C:\Program Files (x86)\Android\android-sdk\tools

To fix this include the path with the script (lame)

monkeyrunner C:001101\Android\test.py

Then it will run (though my script doesn’t really work yet)

Update: It looks like my basic script worked, “worked” meaning it launched the app, which is the only thing it does at the moment, and I am running this in the emulator.