Blackberry 10 Command line development

For BB10 application development, the easy approach is to install the QNX Momentics IDE, to unleash your imagination for developing cool mobile applications. Read a previous article covering the BB10 IDE. There are many situations, however, where a low level control is required, and the command line development tools are indispensable. This guide will show you how to compile and install a Blackberry true native application, using only command line tools.
To get started, we’ll need the command line tools. These are part of the QNX Momentics IDE, so make sure you have it installed.
Step 1: Run a command prompt / shell, go to the location of the QNX Momentics tools, and launch bbndk-env / bbndk-env.sh
Step 2: Using a text editor, write a simple C program, as save it as hello.c:

#include 
int main(int argc, char **argv) {
   printf("Hello World!\nwww.pocketmagic.net");
   return 0;
}

Place it in the same folder with bbndk-env, for convenience.
Step 3: Compile the code with:

qcc -Vgcc_ntoarmv7le hello.c

If you are interested in verbose output, add -v:

qcc -Vgcc_ntoarmv7le hello.c -v

Rename the output to hello (I got a.out as the compiled ELF file)
Step 4: Create the BAR descriptor XML
Every BB10 app must have a BAR descriptor file called bar-descriptor.xml. This is used when installing the app on an actual device. Here is what I’ve used for a minimalistic sample:


com.example.Hello
1
Hello
hello

Where hello is the ELF file generated by qcc . As you can see, the path indicates we have everything in the current folder.
Step 5: Create the bar file:

blackberry-nativepackager -package hello.bar bar-descriptor.xml -devMode -debugToken "\debugtoken2.bar"

The debug token must be valid, and match the one installed on your BB10 device. To locate it (or create it) you can use the Momentics IDE.
If everything goes ok, you will get the hello bar package generated, and a warning:
Warning: Using default icon: C:\home\bbndk\host_10_1_0_132\win32\x86\usr\samples\icons\blackberry-tablet-default-icon.png
Info: Package created: hello.bar

Step 5: Deploy the bar file to a BB10 device

blackberry-deploy -installApp 169.254.0.1 -password 1234 hello.bar

Where 1234 is your BB10 development password. If successful, you would get:

Info: Sending request: Install
Info: Action: Install
Info: File size: 9467
Info: Installing ...
Info: Installing in personal perimeter
Info: Processing 9467 bytes
Info: Progress 100%...
Info: Progress 100%...
actual_dname::com.example.Hello.testDev_ample_Hellodd847581
actual_id::testDev_ample_Hellodd847581
actual_version::1.0.0.1
result::success

And the software can now be seen in the list of programs:
bb10_native_code

More details
You can specify a custom icon in the bar-descriptor.xml , by adding it to assets and then selecting it with the icon tag:


com.example.Hello
1
Hello
The native application, www.pocketmagic.net
icon.png
hello


   icon.png


And place the icon.png file in the same folder. After packing, signing and deploying, here is our program amongst others in the list:
bb10_native_code-2
Notice the nice, custom icon.

Related Post

This article has 1 Comment

Leave a Reply