The other day a pretty scathing critique of the current state of BlackBerry app development was submitted to HN. While the post (from developers at a company called Atomic Object) was absolutely spot on, more interesting to me was a link to one of their older posts describing their development setup on OS X. I had messed around with this a little bit before, trying to get Eclipse and Ant to properly compile BlackBerry apps on OS X, but without success. I didn’t try hard enough apparently.
The post from the Atomic Object team is pretty detailed in explaining how to do this, using IntelliJ and Parallels. The fundamentals are not specific to those tools though, so I followed along and have adapted it to Eclipse and VirtualBox. This gets filed under inane notes about development environments, but as I said when I posted about Emacs and Lisp on OS X, this kind of thing has benefited me in the past, maybe it will help someone else.
- Install Eclipse (I am using 3.5, but it may not matter) and VirtualBox.
- Create a new VM and install Windows (tested with XP SP3). This would probably work using VMWare Fusion or Parallels too.
- On the VM, install Java 6 and the version of the BlackBerry JDE that matches your target OS.
- In OS X, download bb-ant-tools.jar and move it to \~/.ant/lib.
- Get an OS X version of preverify, which is included in the Sun J2ME SDK 3.0 for OS X. Install it and either copy /Applications/Java_ME_SDK_3.0.app/Contents/Resources/bin/preverify to somewhere in your PATH or just add that directory to your PATH.
- If you don’t have one already, create the file \~/.MacOSX/environment.plist.
- Edit this file with /Developer/Applications/Utilities/Property\ List\ Editor.app/.
- Create a new variable called PATH and set it to the value of your shell PATH, making sure that the directory containing preverify is included. This allows Ant, via Eclipse, to see the preverify command when Eclipse is launched from Eclipse.app and not from the command line. See this for more details.
- In OS X, create a directory for the BlackBerry components (something like “bb-components”).
- From the BlackBerry JDE installation in the VM, copy both “lib” and “bin” directories to this directory.
- In Eclipse, create a new Java project.
- Choose “Use an execution environment JRE:” and select Java 1.3.
- Right click the project in the “Package Explorer” and select “Build Path” and then “Configure Build Path.”
- Add bb-components/lib/net_rim_api.jar as an “External JAR.”
- Remove the “JRE System Library.” This is so that only BlackBerry supported classes will be offered via autocompletion etc.
- Copy the attached minimal build.xml into the project.
- Edit the build.xml to suit your environment (specifically the jde.home property) and anything else you want to customise.
- Right click and select “Run as” and then “Ant Build” (the first one). You can also build using Ant on the command line, of course.
Now you should be able to build BlackBerry apps in Eclipse without too much fuss. Testing on the simulator would require you to copy the files to the VM, which can be done by creating a shared drive and copying them there, or connecting to the VM using shh and scp. I use the former, because it’s a little easier to set up. The simulator is not perfect though, and while it runs in VirtualBox, you should really be testing it on a device anyway. So you can use JavaLoader.exe via VirtualBox to deploy to the device.
I had to jump through some hoops to get a BlackBerry connected via USB to work in VirtualBox. What worked for me was to install the BlackBerry Desktop Software for Mac and make sure that it was able to sync the devices I use for testing. Then I was able to enable it in VirtualBox under “Devices” and “USB Devices.”