GDC 2010: Going Google and porting your game to Android

Learning to love the NDK

GDC 2010: Going Google and porting your game to Android
With Google making a splash on the Mobile/Handheld Summit at GDC - thanks in part to giving out free Droids and Nexus Ones - Jack Palevich's talk about Bringing your games to Android was well attended.

The core of the talk concerned the process of bringing existing games to Android; the effective title therefore being Porting your games to Android.

In most cases, this will see C/C++ code being ported, although Palevich pointed out that developers don't need to use native code for Android games. You can use the Android Dalvik (Java) virtual machine for many types of games especially puzzle and strategy.

Making the most

For developers who want to maximise their performance on Android, there's the Native Development Kit (NDK), which enhances the basic Android SDK.

The new version of the NDK has been released, with NDK r3 supporting OpenGL ES 2.0 for the first time.

However, there are a number of issues developers have to be aware of. For one thing, the NDK is based on the GNU (Linux) toolchain so if you're developing on Windows, you have to install the Cygwin package.

As for the porting process itself; it works something like this.

Convert the game to a shared library

Port to the NDK APIs

Compile using NDK

Write a small Java app to call shared library

Package into a game APK (Android's deployment zip file format)

Most of these - changing your build system, porting the game engine, libraries and art assets - should be straightforward. Porting platform APIs calls such as DirectX to OpenGL ES is harder, while non technical features such as reworking controls for touchscreen were pointed out as being one of the largest potential issues.

Taste of Java

Developers will also have to spend time creating the interface between their C/C++ code and the Java Dalvik virtual machine shell which Android uses for deploying games on device and via the Android Market.

Most of this can be copied from the sample code provided via the Java Native Interface, which is the standard way for a Java virtual machine to call C/C++ APIs.

As an example of how the porting process works, Palevich provided details of how he ported glQuake to Android. This required 200 news of Java code, 2,500 lines of new C++ code.

You can find more details, and the code, on the website.

Contributing Editor

A Pocket Gamer co-founder, Jon is Contributing Editor at which means he acts like a slightly confused uncle who's forgotten where he's left his glasses. As well as letters and cameras, he likes imaginary numbers and legumes.