BlackBerry Development Using Linux

VirtualBox

Running Windows in a virtual machine may seem like a cumbersome process but it can be made relatively painless. VirtualBox is very popular and available for most if not all Linux distros. I’m using Ubuntu but you could just as easily apply most of the steps to other distros.

There is an excellent guide here with instructions on how to get it up and running. But here is the short version:

sudo apt-get install virtualbox-ose
sudo gpasswd -a `whoami` vboxusers
sudo modprobe vboxdrv

Launch VirtualBox from the System Tools category in the gnome menu. Hint: to make VirtualBox look a little less out of place in a gtk environment:

sudo apt-get install polymer qt3-qtconfig

Launch qtconfig and select Polymer from the GUI Style list:

Select Polymer GUI Style
Select Polymer GUI Style

I’ll save the boring details of installing Windows in a virtual machine. Here is a list of software that you will need to install in Windows once you have it installed.

  1. Java JDK 1.5+
  2. RIM JDE 4.1+
  3. VirtualBox Guest Additions (Devices menu in VirtualBox)

Host Networking

Now this bit is most important. We need Windows to appear as just another host on the network so that we can connect to JDWP running in Windows from Eclipse running in Linux. We also want to mount a windows shared folder in Linux to quickly copy files to the simulator directory.

It’s not enough to just configure the virtual machine to use Host interface, we need to setup a bridge in Linux too. There are hundreds of guides on the interweb describing how to do this. Google “virtualbox host networking” and you will get tons of great links.

My Network Settings
My Network Settings

I am really only concerned with having two-way communication between Linux and Windows so I am using an unused network interface on my system to setup the bridge. This interface is not connected to my network and gets statically assigned a private IP. If you don’t have a spare interface, or you use wireless networking, see this guide for help.

Required tools:

sudo apt-get install bridge-utils uml-utilities

Script to bring up the bridged interface:

#!/bin/bash
 
MYUSER=$USER
 
# create new bridge
sudo brctl addbr br0
 
# bright down the ethernet interface and add it to the bridge
sudo ifconfig eth0 0.0.0.0
sudo brctl addif br0 eth0
 
# set bridge to static private address
sudo ifconfig br0 10.0.0.1 netmask 255.255.255.0
 
# create tap interface
sudo tunctl -b -t tap0 -u $MYUSER
sudo ifconfig tap0 up
sudo brctl addif br0 tap0

Now simply run the script once prior to starting Windows. In this case the interface on the host (Linux) is not connection to the network and has a static IP so I must also set a static IP in the guest (Windows).

IP Settings in Windows
IP Settings in Windows

In Windows Explorer, locate the directory where you have installed the JDE, right click the simulator directory and click “Sharing and Security”. I think this dialog is different depending on the edition and service pack of windows but for me (XP Pro, SP2) I just had to check “Share this folder on the network” and “Allow network users to change my files”.

Shared Simulator Folder
Shared Simulator Folder

Running the Debugger

Start JDWP in Windows. Back in Linux, mount the Windows shared directory:

sudo mkdir /mnt/simulator
sudo mount -t cifs //10.0.0.2/simulator /mnt/simulator

Use the load-simulator target from the build script in the hello world project to copy the required files over to the mounted simulator directory.

ant load-simulator

Run the debugger! For some reason an exception occurs when using jdb at some point, but simply type resume<enter> to get past it. When using Eclipse, I don’t have this problem.

jdb -connect com.sun.jdi.SocketAttach:hostname=10.0.0.2,port=8000

Seamless Mode

And finally there is one last trick to make using the simulator in a Windows virtual machine a bit more enjoyable: Seamless Mode. Provided you installed the guest additions in Windows you can activate this by selection “Seamless Mode” from the “Machine” menu in the VirtualBox window. This hides the Windows desktop and makes it look like the applications running in Windows are actually running in your Linux desktop.

Simulator running in seamless mode
Simulator running in seamless mode

Comments 21

  1. atleta wrote:

    Hi,

    I made small patch to the ant task so that you can define the ‘exepath’ parameter that is used by rapc to locate the preverify tool. This way you don’t have to put preverify on the path. Actually quite surprisingly rapc first looks for an executable called “preverify” and only if it can’t find it will check for “preverify.exe”. Having just hacked all those backslashes out of the BB tools it’s a bit surprising :) .

    The patch adds a new property to the rapc task called exepath. It should point to the directory containing the preverifier. (I know exepath is a stupid name but preverifierpath would have been too long. I guess that’s why the RIM guys chose it :) )

    You can get the patch from here: http://atleta.dyndns.org:8080/p/opensource/bb-ant-tools/exepath.patch

    Let me know if you integrated it. My e-mail address is atleta and the domain name is atleta.hu. Join the two with an @…

    Posted 23 Jul 2008 at 9:15 am
  2. jiGGaK wrote:

    Thanks atleta,

    This patch will be applied to the trunk.

    It really is amazing how solid the rapc tool is considering how flimsy the other tools are. I guess for that we should be thankful.

    Posted 23 Jul 2008 at 11:19 am
  3. Derek Konigsberg wrote:

    Actually, I recently discovered that RAPC does have a slash-vs-backslash problem like the other tools. You just don’t encounter it until you try building resource files into your project. However, it can be fixed with the same techniques outlined elsewhere on this site.

    Posted 06 Aug 2008 at 4:59 pm
  4. jiGGaK wrote:

    Derek,

    That’s funny, I’ve yet to run into that problem. By resources, are you refering to .rrc and .rrh files?

    Posted 06 Aug 2008 at 5:53 pm
  5. Patrick Waugh wrote:

    Awesome, but once I set to host mode, my virtual host will not boot :(

    Posted 18 Sep 2008 at 4:56 am
  6. jiGGaK wrote:

    Patrick,

    Can you expand on that? Does virtualbox fail to start the guest, or does the guest OS fail during boot?

    Posted 18 Sep 2008 at 9:35 am
  7. Patrick Waugh wrote:

    @jiGGaK

    The guest OS failed to start the guest. I get this:

    Failed to open ‘/dev/net/tun’ for read/write access. Please check the permissions of that node. Either run ‘chmod 0666 /dev/net/tun’ or change the group of that node and make yourself a member of that group. Make sure that these changes are permanent, especially if you are using udev.
    VBox status code: -3100 (VERR_HOSTIF_INIT_FAILED).

    and this:

    patrick@berrysoft:~$ ls -l /dev/net/tun*
    crw-rw—- 1 root root 10, 200 2008-07-02 05:16 /dev/net/tun

    so I did this:

    patrick@berrysoft:~$ sudo chown :vboxusers /dev/net/tun
    patrick@berrysoft:~$ ls -l /dev/net/tun*
    crw-rw—- 1 root vboxusers 10, 200 2008-07-02 05:16 /dev/net/tun
    patrick@berrysoft:~$

    and now it boots. Thanks for offering to help.

    I just had to do a little more man page reading. =)

    Posted 28 Sep 2008 at 2:27 am
  8. Cody A.W. Somerville wrote:

    Hi,

    I read that barry has indeed successfully implemented the javaloader in trunk. :) I haven’t tested it yet but I just bought a blackberry and am very eager to do some blackberrry developer on Linux.

    Have you tried the new eclipse plugin? Do you know it that works on Linux?

    I’d love to chat more about BB development on Linux! Feel free to send me an e-mail.

    Cheers,

    Cody

    Posted 11 Feb 2009 at 8:27 pm
  9. David A. Desrosiers wrote:

    I can’t get your hello world to build at all, regardless of where I put the JDE (4.2.1 or 4.7.0). It fails as follows:

    /tmp/test/hello/build.xml:12: jde home missing “lib” directory

    Of course, the JDE doesn’t HAVE a ‘lib’ directory at all inside it, nor should it.

    How did you build this, if not against the RIM JDE 4.2.1 or 4.7.0?

    Posted 12 Aug 2009 at 1:52 pm
  10. jiGGaK wrote:

    David,

    What does your JDE directory structure look like? Every version of the JDE I have come across has a “lib” directory.

    Here is what my 4.2.1 JDE structure looks like:

    ./bin
    ./bin/DefaultBuild.rc
    ./bin/DefaultWindow.rc
    ./bin/FixedBuild.rc
    ./bin/IDE.jar
    ./bin/JDWP.jar
    ./bin/JavaLoader.exe
    ./bin/RimUsbJni.dll
    ./bin/Runtime.rc
    ./bin/SignatureTool.jar
    ./bin/SimPackage-JDE.rc
    ./bin/UpdateJad.exe
    ./bin/focusFlipper.exe
    ./bin/ide.bat
    ./bin/jdwp.bat
    ./bin/launcher.exe
    ./bin/preverify.exe
    ./bin/rapc.exe
    ./bin/rapc.jar
    ./docs
    [snip]
    ./lib
    ./lib/net_rim_api.jar
    ./samples
    [snip]
    ./simulator
    [snip]
    
    Posted 12 Aug 2009 at 2:13 pm
  11. David A. Desrosiers wrote:

    Well, after installing both JDEs on Windows, and copying over, it replicated the correct structure. I have no idea what happened before, but now I can build the hello sample.

    Now off to figure out how to fix the broken SDK, so I can build the Funambol Blackberry client using this same process.

    Posted 13 Aug 2009 at 7:13 pm
  12. David A. Desrosiers wrote:

    Oh, and thanks for setting me on the right path :)

    Posted 13 Aug 2009 at 7:13 pm
  13. kiran wrote:

    sir/ madam
    please let me know briefly the application of linux in the industries. is linux an imporatnt language to be learnt.

    Posted 02 Sep 2009 at 11:17 pm
  14. kiran wrote:

    i am in eager to learn it. learning them is essential is of any industrial importance.

    application possible with linux??

    Posted 02 Sep 2009 at 11:20 pm
  15. jeffry james.p wrote:

    i want to know how linux developed &development uing linux

    Posted 02 Sep 2009 at 11:25 pm
  16. David Aurelio wrote:

    Thank you for the helpful post. Really saved my day.

    Posted 08 Apr 2010 at 11:54 am
  17. Pam wrote:

    I’m missing something, I installed everything, I could even run the simulator from your other post, but I don’t know where to put the /lib dir from the JDE and when I run ‘ant’ inside hello i get:
    BUILD FAILED
    ~/hello/build.xml:12: jde home must be a directory

    Any help would be appreciated.
    Thanks

    Posted 06 May 2010 at 5:47 am
  18. Gwan wrote:

    Great post, really!
    It worked for me, but I still have an issue with rrc/rrh files. If I look at the .crb corresponding files generated in the jar, they differ at the and of the name with those generated on windows. I.e. the file names in linux are ca.slashdev.FooApplication?.crb, as they are ca.slashdev.FooApplication-รบ.crb in windows. It must have something to do with caracter encoding, but I can’t figure out how to fix it. If anybody has managed to use localization of resources under linux, please post the fix.
    Thx

    Posted 19 May 2010 at 2:17 pm
  19. Gwan wrote:

    Figured it out:
    export LANG=”en_US.ISO-8859-1″

    Posted 20 May 2010 at 9:01 am
  20. Alexey Potapkin wrote:

    I have a problem with a project with a lot of .java files (over 1000). At first I had “Create process error=87″ problem at java start. It was solved by adding “generatesourcelist=”true”" flag to ant task. And now i stuck at the similar problem that appears at javac start. It looks like
    [rapc] I/O Error: Cannot run program “javac”: CreateProcess error=87, The parameter is incorrect. Anyone can help me?

    Posted 30 Aug 2010 at 6:09 am
  21. jiGGaK wrote:

    Alexey,

    Try searching the bb-ant-tools mailing list. I know something similar to this topic has been covered there before.

    http://sourceforge.net/mailarchive/forum.php?forum_name=bb-ant-tools-general

    Posted 30 Aug 2010 at 6:32 am

Trackbacks & Pingbacks 3

  1. From Slashdev - A Notch in the Cross Platform Blackberry Development Belt on 11 Mar 2009 at 9:03 am

    [...] a previous post I listed 4 key items needed for BlackBerry [...]

  2. From Linux ?? BlackBerry ?????????? » ?????????(Giraffy) :: ???????????????? on 25 Nov 2009 at 1:32 am

    [...] http://www.slashdev.ca/2008/04/03/blackberry-development-using-linux/ [...]

  3. From Cracking Berries, Windows, and Necks « MentalPolyphonics on 23 Feb 2010 at 7:40 pm

    [...] an OSX development environment — just Windows — so I’m forced to work through the Linux hacks for doing Berry dev on unix-like [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *