BlackBerry 10: Getting the Cocos2d-x Hello World app to build
This article explains how to get the sample 'Hello World' project building in Cocos2d-x. I had some difficulty getting it to compile and run. My goal is to eventually port my game Pocket Bombs from iPhone to BBX. As the iOS version is written in cocos2d for iPhone I hope to be able to quickly port it over once I figure out the BlackBerry port of the API.
References:
- BlackBery NDK Beta 3 [developer.blackberry.com]
- Cocos2d-x [cocos2d-x.org]
- How to run HelloWorld and Tests on BlackBerry Tablet OS [cocos2d-x.org]
- How to build project by using bbndk1.0 and bbndk2.0 [cocos2d-x.org]
- Cocos2d-iphone [cocos2d-iphone.org]
- Adding library to linker in BB10 [supportforums.blackberry.com]
- Using custom fonts with the NDK [supportforums.blackberry.com]
How to get a Cocos2d-x Hello World project to build
I am using the BlackBerry 10 SDK Beta 3. YMMV if you use a newer/older version:
- If you don't already have it installed, install the BlackBerry NDK from RIM's Website
- Download & extract the archive from the download page
- Run the create-blackberry-project.vbs script and give the project a name
- Create a new workspace in the Momentics IDE (Eclipse for BB10)
- Copy over the cocos2dx and CocosDenshion projects to the workspace using Windows Explorer
- Copy over the project you created in step 2 into the workspace using Windows Explorer
The reason why I have you manually copy these folders over is because I had issues when I tried to 'import and copy' feature in the IDE - From within the IDE, Go to File -> Import then select General -> Existing Projects into Workspace and import the Blackberry project files that are in your workspace. Please note that there are other projects in the list aside from blackberry that you do not need so you don't have to select them.
- Build the cocos2dx project
- Build the CocosDenshion project
- Build your project
If all goes well your project should be ready to run on your Dev Alpha device / Simulator. If, however, you get an error about FT_New_Face font ('FT_New_Face' is defined in DSO C:/bbndk_10_0_9/target_10_0_9_386/qnx6/armle-v7/usr/lib/libfreetype.so.1 so try adding it to the linker command line), continue on to Step 11 - Right-click on your Project and select Configure -> Add Libraries... and select Standard BlackBerry Platform Library
- From the available list, select Freetype2 finish the wizard and save/apply to your project
- Right-click on your Project and select Properties -> C/C++ Build -> Settings -> Tool Settings Tab -> QCC Linker option -> Libraries
- Select the freetype2 library and edit it (button to edit is tiny and in the 'Libraries' header section of the window). Make sure to change it to read freetype (Drop the 2). The image above in 11 shows this already done. This is an important step or you'll see errors about lfreetype2 not being able to be linked
- Open the bar-descriptor.xml file and remove any line that looks like this: < asset path="libfreetype2.so" type="Qnx/Elf">lib/libfreetype2.so< /asset>. See this screenshot for an example of what should be removed:
At this point things should be building correctly for you. I was able to get the test project to work on my Dev Alpha device. Hopefully this is a solid platform for me to use to port PocketBombs to BBX. Given that RIM has invested som engineer time into the project I have some degree of confidence that it will meet my needs.