Sibling CODs – or How to Make Your App Install Over The Air

It’s been way too long since I wrote a post – interesting aside for bloggers: don’t get out of the rhythm, it’s incredibly hard to start back up again once it’s no longer part of your daily routine. Anyway, I’ve been busy (more on that later) but due to demand am now committed to start posting again, and it was a recent comment on an earlier post that gave me the idea for this one: short but sweet and valuable to all aspiring BlackBerry app developers.

Big CODs

BlackBerry applications are compiled using the RAPC tool (which is called automatically by the JDE or the JDE Plug-in for Eclipse) into .cod files (pronounced like the fish by most developers). A .cod is basically a .jar file, which is further compressed, optionally signed, and has any unused code removed. They’re only usable by the BlackBerry – no other J2ME devices.

Because of some deep technical reasons (I think to do with the way the flash file system used to work on the device) a .cod file can only be a certain size. Or more correctly, a .cod file can only have a certain amount of code or static data (resources mostly). That limit is about 64k – so theorietically a .cod file could be almost twice that limit, with 64k each of code and data, but in practice that never happens, and in fact there seems to be another limit. In any case, the exact number isn’t all that important – the point is that most modern applications have no trouble breaking through either or both of those size barriers.

So what happens when you make an application that produces a .cod that’s too big? The RAPC compiler breaks the .cod into smaller .cod files, and renames them based on your initial .cod file. So instead of having:

File Size
myapp.cod 552,966

You get something like:

File Size
myapp.cod 58,016
myapp-1.cod 56,380
myapp-2.cod 57,980
myapp-3.cod 55,528
myapp-4.cod 53,816
myapp-5.cod 52,968
myapp-6.cod 50,004
myapp-7.cod 57,252
myapp-8.cod 53,772
myapp-9.cod 56,224

Or at least – that would make sense. Actually it’s something slightly different.

Sibling COD files

In reality what you get is:

File Size
myapp.cod 552,966

So what gives? Well if we take a closer look at that big cod file, what you’ll notice is this: it’s actually a .http://winrar.comzip file! That’s right, http://allbeautyreviews.com/makeup – rename it to myapp.zip and open it and inside you’ll see:

File Size
myapp.cod 58,016
myapp-1.cod 56,380
myapp-2.cod 57,980
myapp-3.cod 55,528
myapp-4.cod 53,816
myapp-5.cod 52,968
myapp-6.cod 50,004
myapp-7.cod 57,252
myapp-8.cod 53,772
myapp-9.cod 56,224

Those similarly-named files inside the big .cod/.zip file are called sibling COD files.

So What?

So, ok all your .cod files are packaged up into a .zip. Sensible, right? Just load that one file and everything works. Well, that’s true, except if your trying to download your app to your BlackBerry without using a BES. Understand that sentence – you can load one big .cod file if you’re doing it through the desktop manager, or if you’re downloading through a BES, but if you’re not attached to a BES and want to download it directly to your device, you’re out of luck.

Fortunately the solution is relatively simple – just unzip that big .cod/.zip and post all the individual files to the same directory, along with the .jad file. Then things will work fine – the browser will even know enough to show the user the total app size before downloading.

In fact, if you want to automate all that, I recommend the excellent (and free) bb-ant-tools, which includes a nice Ant task called jadtool that does the unzipping of the sibling cods for you.

So there you go – sibling CODs!