Recently I tried out Cordova for BlackBerry OS 7 and earlier. I know BB7 isn’t exactly a new topic, and if a “trendy” developer chooses to dig into BB this moment, they might as well just start with BB OS 10. For me, I still use an “old-generation” BlackBerry, and being able to dev something for myself sounds pretty much attractive… plus, it’s my personal liking 😀
After a few days working with PhoneGap 2.7.0 (latest stable version at writing time) and Ripple Emulator 0.9.16 Beta (also latest version at writing time), I realize there’re a few possible headaches you might run into – even if you launch a fresh PhoneGap “HelloWorld” example project – meaning it’s not you who are at fault, but something else is being fishy. They are as follow:
1. Ripple Emulator will log a console message, denoting you have an issue with your app version or configuration. The exact message is this: “cordova :: Your application does not appear to match the platform you have selected. The version number in your configuration might not match the selected platform version or your configuration file has errors in it.”
Although this warning message doesn’t harm your app in any way, those fussy developers out there (like me) will not sleep soundly as long as the warning remains on screen. Here’s the solution: in your project “config.xml”, add the “gap” namespace attribute into the “widget” tag. The exact block of code to use is this:
xmlns:gap = "http://phonegap.com/ns/1.0"
And thus your config.xml “widget” tag may look something like this, in the end:
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:gap = "http://phonegap.com/ns/1.0" version="22.214.171.124" id="MyWonderfulApp">
With this configuration, Ripple will no longer display the warning. Happy eh!
2. The event “deviceready” doesn’t get fired.
At first sight, this appears to be a serious issue. In fact it took me days to understand the full story behind. The funny thing is: the event DOES get fired, but it’s only fired AFTER the system has done loading the file “cordova_plugins.json“. This file is not included in the default example project folder, and in fact this file may have any content as your app won’t be using it (at least for PhoneGap version 2.7.0). The browser behavior is that if it cannot find this file or this file exists but doesn’t have any content (empty text file), it will keep “pending” at that step, thus postponing the “deviceready” event till a much later time, when it finally times out.
You might be curious as to how I found out this.. Well I was testing my app, something like the 31st time.. without “deviceready” being fired. Being tired and worn out, I finally gave up and took a nap. It was when I woke up seeing the event fired did I realize the hows and whys of everything 🙂
So anyway, the solution is simple: create the “cordova_plugins.json” file in your project www folder with any content inside. For me I was using this text: “DUMMY”. After this, the browser won’t have any issues loading your app, and “deviceready” would finally be fired on time. Woah.. hope you guys haven’t been on fire for too long, trying to solve this funnily deadly issue!
Again, I’d love to note that this happens to me under these 2 conditions: Cordova version 2.7.0 and Ripple Emulator 0.9.16. You might not run into the same issues under different tools but if you do, I still hope this post would be able to provide some useful information.
Hope this helps 🙂