User Tools

Site Tools


This is an old revision of the document!

Compiling for Android from Windows

NEW: 3/12/2012 - Proton no longer requires Cygwin to be install to compile android apps on Windows!

Originally the Android platform was crippled by requiring all “app” code to be written in Java.

In OS 1.5, the NDK (Native Development Kit) was introduced. Used with Proton SDK you get the following advantages:

  • Native ARM machine code is faster than using Java
  • The ability to use millions of lines of existing legacy C++ code
  • Can use boost and stl (since r5 I think..)
  • Can write an Android game without writing a single line of Java
  • Can debug your app in MSVC or Xcode
  • Can also code parts in Java if you really need to
  • Can write standard GL code in C/C++

The way Proton SDK handles each target, be it iOS, WebOS, or Android is by using glue code that isolates the game code from the platform specific API.

The C++ “glue” code for Android is located in /shared/android and the .Java parts are in /shared/android/src. These are shared between all applications so be careful if you touch them.

Side Note : There is actually an even newer way to do NDK now - something called a NativeActivity where you can use 100% C++. Except you can't, because things like IAP and Tapjoy integration would still be in Java so I assume more ugly bridging would be required.. also it requires Android 2.3+ (boo, hiss), but I plan to do an android target supporting this eventually, especially since it seems to be the only way to fully support the xperia play gamepad controls. -Seth


Before attempting to move on, you really should already have done this:

NOTE (MK): RTSimpleApp, you need to do the “Building resources” step. Otherwise, the app will crash/exit right away, and you'll get the “Can't load font 1” error mentioned.

Section 1: Setting up your Windows computer to compile for Android

Get ready to do some downloading and installing! Android might be the most complicated one to setup, but you're in luck, the latest NDK no longer requires installing cygwin so it just got a lot simpler!

Important note: For all this stuff, try to choose a custom install path WITHOUT spaces in it. There, I just saved you like 40 minutes of diagnosing vague errors that will happen later. No charge, friend!

  • Install the Android SDK - use the Windows exe version so it will also prompt you to install the Java SE JDK which will be needed as well.
  • Add C:\whatever\android-sdk\platform-tools to your windows path
  • Add C:\whatever\Android\android-sdk\tools to your windows path

If you type “android” from the DOS prompt it will bring up the Android SDK and AVD Manager. This is where you create AVDs (basically, emulator profiles, if you want to use the emulator) and can install optional libraries.

Here is how I setup my AVD (note my naming format.. helps later to remember which AVD is which version)

Make sure you install “USB Driver package, revision X”, your phone probably needs this. Also, “Market licensing package, revision X” is needed.

Note: I had problems on Win7 until I found “android.bat” and ran it with “Run as administrator”.

Another note: The emulator refused to start until I edited the path to be a dos 8.3 format. (Ie, C:\PROGRA~2\Android\android-sdk\tools instead of C:\Program Files (x86)\Android\android-sdk\tools - you can use dir /x to get the exact name to use)

You want to test on your real device(s), right?

Driver links for your device:

Setup your Android device like this:

  • In Settings→Applications enable “Unknown sources”. Otherwise you can't test your apps.
  • In Settings→Applications→Development enable “USB debugging”
  • After plugging in your phone, in the Win device manager it will probably say “no drivers installed” - click update driver and install them
  • Typing “abd devices” should show your plugged in phone as a device now. If so, congrats, you got this far!

Ok. In theory, you're now setup for building a standard Android app and running it in the emulator or on your device. (The emulator truly emulates, it can use the same file)

You don't absolutely have to, but if you run into any snags in the install later, come back to this point and try installing Eclipse (get Eclipse IDE for Java Developers) and building a “hello world” app to test everything thus far. Nice tutorial on doing that is here. Actually, don't, waste of time probably.

Android is complex and I don't really think p+ can shield you from its intricacies. You still need to know how to create an AVD emulator, understand what a .manifest is and know what obscure error messages like “Committing suicide to kill the zombie!” mean. Well, bad example because I still don't know what that error message really means.

You should probably spend a few days of hacking around with hello world apps to get a feel for it before attempting to use Proton SDK with it.

Section 2: Downloading and setting up the NDK and compiling RTBareBones

Ok, typing adb from the dos prompt shows your device and you seem good to go to the next step.

First, mentally throw away Eclipse if you were using it for testing - you'll never need it again.

  • Install Ant, grab the latest .zip (v1.8.2 at this time) and unzip it to somewhere.
  • Add the ant directory to your windows path. Verify it's working by typing “ant” in a dos prompt, it should do something other than “bad command or file error”.
  • Download the Android NDK and unzip it somewhere. Again, put it somewhere with no spaces in the filenames if possible. (Not “Program Files”!)

Note: The NDK version should be r7b (latest at the time this was written) or later.

Another Note: NDK r7b is slightly broken, it won't run on a Xoom/tegra2 chipset! check this for a work around)

Ant is command line utility that will do the Android packaging for us after the .so binary is built.

Annoying stuff you have to do:

  • Add your android ndk dir to the windows path
  • Edit RTBareBones/android/app_info_setup.bat and set the variables up if different, note that you can set the emulator AVD name you wish to use.

Finally, the compile!

Get ready to open the champagne because we're about to compile!

From file explorer, double click /RTBareBones/android/build.bat

You should see a bunch of weird warnings like “this precompiled header message should show up once” showing up forty times. This is all perfectly normal. Trust me. Also, help me fix this, as the Android compiles are horrible slow.

After a lengthy C++ compile process, it then compiles the Java pieces in one second, then slowly puts it on the active device, as long as you only have one plugged in. The .apk it makes is located in /RTBareBones/android/bin in case you want to give it to someone else to test with.


  • build.bat uses InstallOnDefaultPhone.bat which installs it to whatever device is plugged in, as long as only one device exists, it works.
  • If any headers change, use FullRebuild.bat or Clean.bat. Otherwise you can run into a situation where it seems like it compiled fine but crashes.
  • Compiling is very slow. This would drive me crazy except that I generally do it very rarely, as I can do 99% of the dev in MSVC where a recompile takes seconds. The java part takes nearly no time, so no problem there.

Run ViewLog.bat to see the debug output from the emulator, or ViewLogDefaultPhone.bat to see the debug output from your device.

Customize the .mak

If you need to add remove source files to the project, manually edit RTBareBones/jni/

Also, if you're having trouble, it's a good idea to enable debug mode compiling. To do that, change:

#release flags

#debug flags


#release flags

#debug flags

Don't forget to change it back later.

Note: The above is sort of outdated and instead of LOCAL_CFLAGS/LOCAL_CPPFLAGS it's actually SHARED_FLAGS or MY_FLAGS to avoid duplication.

Enabling the Android Market Licensing Verification Library

If you want to sell your App in the Android market, you should use LVL.

It's actually already implemented in Proton SDK, take a look at the only .Java file in RTBareBones, located in RTBareBones/android/src/com/rtsoft/rtbarebones

//This is the only app-specific java file for the android project.  The real work is done in
//shared/android/src/rtsoft/shared/  When editing that, be careful, as it is used
//by all Proton projects.
//Thanks to Phil Hassey for his help and code
package com.rtsoft.rtbarebones;
import com.rtsoft.shared.SharedActivity;
import android.os.Bundle;
public class Main extends SharedActivity
    protected void onCreate(Bundle savedInstanceState) 
		BASE64_PUBLIC_KEY = "uh, it would go here if you had one and wanted to use the google licensing stuff";
		PackageName= "com.rtsoft.rtbarebones";
		dllname= "rtbarebones";
		securityEnabled = false; 

You would just need to enter your public key (The Google developer console gives this to you after you sign up) and change “securityEnabled” to true.

Final thoughts and tips

That's about it for getting the samples running on Android.

Use the same process to compile RTSimpleApp and the others.

  • Want to clone one of the example apps to be the starting place of a new app? Then read the tutorial on how to create a new project by copying from a Proton sample app.
  • Want to compile faster? Change call ndk-build in build.bat to call ndk-build -j8 (or lower than eight if you don't have 8 threads on your multicore cpu)

V2 Android setup

RTAdTest actually uses a new v2 setup, it has a preprocessing step to be able to include/not include certain java code and control package naming.

It supports Android market IAB, Tapjoy, and Hooked. No other examples currently use the v2 setup, but all new stuff will.

proton/android_setup.1331678438.txt.gz · Last modified: 2012/03/13 22:40 (external edit)