how to test a local web application in droid simulator

In August, I blogged about how to use the blackberry simulator because information was so scarce.  I’m happy to say the Android emulator documentation is much better.

My goal

About a month ago, beta testers of  JavaRanch’s JForum implementation told me the iPhone and the Droid had a large blank column on the right side of the screen.  Hence needing an emulator to try to fix it.  (This all happened weeks ago – just didn’t get around to blogging about it.)

Note: I didn’t install the Android Eclipse plugin because I’m not doing BlackBerry development.  If you want the plugin, you can install the toolkit.

Steps to download the simulator

  1. Download the SDK for your platform from the Android download site.
  2. Run “SDK Setup” executable from the download
  3. Choose the required available packages for download.  (I wasn’t sure what I needed so I had downloaded all of them.  You definitely need Android 2.0.) .  This step took a long time to install since it downloaded at 55KB/sec – dialup speeds.  I let it run overnight to completion.  It probably took a few hours.

Steps to initially configure the simulator

  1. See what targets are available
    android-sdk-windows\tools>android list targets
    “Android 2.0” version 5 should be a choice. This is the Droid.  The target looks like:
  2. id: 1 or “android-5”
    Name: Android 2.0
    Type: Platform
    API level: 5
    Revision: 1
    Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854
    etc

  3. Create the AVD (Android Virtual Device)
    android-sdk-windows\tools>android create avd -n Droid -t 1

Launching and running

  1. Launch your local Tomcat (or other app server)
  2. Launch the emulator
    android-sdk-windows\tools>emulator -avd Droid
  3. wait a while – it says “Android…” then “ANDROID” in shiny letters
  4. Ignore error message that says “sorry application messaging is not responding”
  5. Test away.  Note that you must use your computer name rather than localhost.  (On windows this is the %COMPUTERNAME% property.)  Thanks to ASP forum for this tip.

Actually using the simulator

Some impressions of using the simulator:

  • It’s great and intuitive.
  • That’s it!  If you read my BlackBerry post, there were a pile of things to get used to.  The Droid just worked.

The goal

The trick is that the Droid and iPhone need to be told the width of the page or they assume it is larger.  It’s an odd effect, but easy to solve by adding the following tag to the header.

<meta name="viewport" content="width = 320" />

memory profiling with jvisualvm

I’ve been meaning to blog about jmap/jvisualvm for a while, but this JavaRanch question finally prompted me to do so.

My goal was to see where the memory was going in our JForum installation at JavaRanch. This was a one time thing, so I decided to see if I could do so without JProbe.   A colleague had already used Eclipse’s Memory Analyzer.  (Awesome tool by the way – it clues you right in to what it suspects are leaks.)  I decided to use jvisualvm.  Which was interesting.  While I was off exploring, someone else solved the problem and I put writing this up on the side.

I tried this locally on my machine to make sure I knew what to do before trying it on the production UNIX/Linux box.

How to run jvisualvm

  1. Get your process id:
    • Windows: JPS can be used to find your process id on windows.  At the DOS prompt, type “jps”.  My Tomcat process is called “bootstrap”  [I figured this out by stopping the process, running jps and then restarting the process running jps again.  I also had an unnamed process (Eclipse maybe?) and for jps itself.]  The JavaDoc says jps may not be supported in the future, but it works right now on Windows XP.
    • UNIX: You can simply use ps -ef | grep <whatever makes your process name identifiable>.  In my case, it was “ps -ef | grep coderanch”
  2. Run “jmap -dump:file=heap.bin.hprof 1234” [if your process was 1234].  Note this requires Java 6.
  3. Run “jvisualvm”
  4. file –> load –> choose hprof file from jmap
  5. Filter by classname – I used the package name net.jforum to narrow things down.  Which turned out to be a mistake as the memory leak was in Lucene.

or – Run” jhat -J-mx512m heap.bin.hprof”.  Thanks to this blog for helping with the jmap/jhat command.

[edited to fix typos]

how to test a local web application in blackberry simulator

Surely there must already be a tutorial on this, but I didn’t see one.  I did see this information scattered amongst various places.  So here it is in one place.

My goal

Make JavaRanch’s JForum implementation more mobile friendly.  It’s not too bad on the iPhone because the iPhone has a better browser.  On the BlackBerry, the forums are much more difficult to use than they need to be.  As a result I plan to starting out by testing a mobile stylesheet with the BlackBerry simulator.  I found an online iPhone simulator.  After the mobile stylesheet looks on the BlackBerry simulator, I can upload it to a test server and try with the iPhone one online.

Note: I didn’t install the BlackBerry Eclipse plugin because I’m not doing BlackBerry development.  If you want the plugin, I did come across a very detailed tutorial.

Steps to bring up app in BlackBerry simulator

  1. From the BlackBerry download site, download both the simulator and the MDS package.  You need the later in order for the simulator to do internet.  If you have a slow connection, note that both are large downloads.  The simulator is 82 MB and the MDS is 45 MB.  (Note to RIM: if one is already running Tomcat, it would be nice to distribute this as a web app.  Smaller download, no need to change to port and less of a memory hog.)
  2. If you are already using port 8080 (such as to run your own Tomcat server.) Open the file “..\Research In Motion\BlackBerry Email and MDS Services Simulators 4.1.2\MDS\config\rimpublic.property” and change the “WebServer.listen.port” property from 8080 to 8081.  Thank you BlackBerry message board for this tip.
  3. Launch the MDS
  4. Launch the BlackBerry Simulator
  5. Launch your local Tomcat
  6. Test away.  Note that you must use your computer name rather than localhost.  (On windows this is the %COMPUTERNAME% property.)  Thanks to ASP forum for this tip.

Actually using the simulator

Some impressions of using the simulator:

  • It defaults to “100%” view.  100% of what?  No BlackBerry is that big!  On a 1024×768 resolution, the screen and keys don’t both fit on the screen.  I immediately switched to 50% view which is about an inch longer than an actual BlackBerry.
  • Luckily the keyboard works without having to click on the simulated device keyboard.
  • All the buttons have a real keyboard shortcut which you can see when mousing over the simulated key.  This helps with frequent operations.
  • To use the scroll wheel, you have to click and drag.  I would have expected mouse gestures to work here because they are more similar to what you do on the device.  Luckily there is a keyboard shortcut for this (hold F9 and use arrows to your heart’s content.)
  • It grays out if you don’t use it for a few minutes.  As does the real BlackBerry.  This is a bit annoying when testing though.
  • Luckily you can paste in from the real system clipboard – useful for testing URLS

Now that I’ve gotten used to the simulator, the site is just as hard to use on the simulator as it is on a real BlackBerry.  Perfect!  That means it suits my needs.

Problems/error messages I encountered

Since most people look for a “problem/solution”, I’m also listing the surprises in that format.  I know that’s what I was looking for!  I didn’t think I’d need a tutorial on setting up a simple piece of software.

  • BlackBerry simulator hangs when I try to access the internet – check you have installed the MDS, turned it on and you don’t have a port conflict
  • 8080 in use when starting MDS – see step #2 and change the port #
  • 403 error accessing localhost – see step #6 and use the computer name
  • Fledge.exe is using a lot of memory – this is the blackberry simulator itself; not much you can do here

The goal

I saw just how bad things look.  There’s a few more steps before actually making it look better – like getting rid of the table based layout.  But I did make progress with the tool support!