This is an old revision of the document!
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:
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.
Get ready to do some downloading and installing!
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!
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)
Having said that, the truth is I never use the AVD/emulator stuff, it's too slow and useless.
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:
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 what a .manifest is and you'll be seeing obscure error messages like “Committing suicide to kill the zombie!”. Well, bad example because I still don't know what that error message really means.
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.
Note: The NDK version should be r7c (latest at the time this was written) or later.
Ant is a command line utility that will do the Android packaging for us after the .so binary is built.
Annoying stuff you have to do:
Get ready to open the champagne because we're about to compile!
From file explorer, double click /RTBareBones/android/build.bat
After a lengthy C++ compile process, it then compiles the Java pieces in one second, then 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.
Run ViewLogDefaultPhone.bat to see the debug output. (As long as only one device is plugged in/active, it will work, be it the emulator or a real device)
If you need to add/remove source files to the project, manually edit RTBareBones/jni/Android.mk.
Also, if you're having trouble, it's a good idea to enable debug mode compiling. To do that, change:
#release flags LOCAL_CFLAGS := -DANDROID_NDK -DBUILD_ANDROID -DGC_BUILD_ANDROID -DNDEBUG LOCAL_CPPFLAGS := -DGC_BUILD_C -DANDROID_NDK -DBUILD_ANDROID -DNDEBUG #debug flags #LOCAL_CFLAGS := -DANDROID_NDK -DBUILD_ANDROID -DGC_BUILD_ANDROID -D_DEBUG #LOCAL_CPPFLAGS := -DGC_BUILD_C -DANDROID_NDK -DBUILD_ANDROID -D_DEBUG
#release flags #LOCAL_CFLAGS := -DANDROID_NDK -DBUILD_ANDROID -DGC_BUILD_ANDROID -DNDEBUG #LOCAL_CPPFLAGS := -DGC_BUILD_C -DANDROID_NDK -DBUILD_ANDROID -DNDEBUG #debug flags LOCAL_CFLAGS := -DANDROID_NDK -DBUILD_ANDROID -DGC_BUILD_ANDROID -D_DEBUG LOCAL_CPPFLAGS := -DGC_BUILD_C -DANDROID_NDK -DBUILD_ANDROID -D_DEBUG
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.
The only app specific .java file is located in /android/src/Main.java. It has some options for enabling security, Tapjoy, Hooked, and such.
That's about it for getting the samples running on Android.
Use the same process to compile RTSimpleApp and the others.
If you look at android/build_prepare.bat you'll see a lot is going on. It's actually taking a bunch of android files from /shared/android/v2_src and running a preprocessor step on them using ant. (JavaPP (javapp.jar) is copied to your ant dir)
The preprocessor allows #define and #ifdef stuff to work in java, and also replaces the package name with your own. It also runs on AndroidApp.cpp and modifies the JNI bindings to match the package name.
When you're done building, you can see what it changed by looking in the temp directories android/temp_final_cpp_src, andriod/temp_final_src.
build_prepare.bat also also where it copies any required 3rd party sources/libraries into the app's libs directory, such as Google's billing stuff, Tapjoy or Hooked. (No preprocessor is run on those)
Most examples use the new V2 android setup, but a few older ones don't. (RTPhysics?) The old method didn't have the preprocess step which created problems later when enabling IAP and such or including/removing libraries on the java side flexibly.