Chapter 8. Interacting with other languages

 

Android applications are coded mainly in Java. Officially, Android also supports C/C++ using the Android NDK (Native Development Kit). But is it possible to develop applications using other programming languages? In this chapter, we’ll analyze the other possibilities.

Hack 33 Running Objective-C in Android: Android v1.6+

During the summer of 2011, my company released an iOS game called Shaman Doctor. The game was developed using cocos2d-iphone, an iOS library. The cocos2d-iphone library is coded in Objective-C, but there are a lot of forks that offer the same API in other programming languages. One of the most active forks is cocos2d-x. Instead of using Objective-C, cocos2d-x uses C++, and the most interesting thing about this project is that the API looks like Objective-C. To get an idea of what the Cocos2d-x team has created, take a look at the following code:

As you might have noticed, the API is exactly the same, but to port a game from cocos2d-iphone to cocos2d-x you would need to port all your Objective-C code to C++, which is a boring task.

When I started looking for alternatives, I found a library called Itoa created by Dmitry Skiba. To understand what Itoa is capable of, let me quote its documentation (see section 33.5):

[Itoa] is a cluster of open-source projects hosted on GitHub that implement compiler, build scripts and various libraries to allow building Android’s apk from Objective-C source files.

Hack 34 Using Scala inside Android: Android v1.6+