The goal today is to get the Galcon codebase to compile using the NDK. This will create a single .so file which will be accessed via JNI.
Step 1 – Downloading the NDK:
Download the NDK for native C/C++ code. I plan on doing as little Java as possible, so I’m going to find out how well this stuff works.
Step 2 – Building a NDK sample:
Trying to build an NDK sample. I went into ndk/samples/<whatever> and ran ../../ndk-build (as per instructions in previous link). This worked fine.
But when running in Eclipse, I had some trouble with some examples, but not with some of the other ones. I’m not sure what that is about, but for now I’m going to forge on and not worry about it.
Step 3 – Preparing my project for the NDK:
I’ve created an android folder in my Galcon project for storing all this ports info. I’ve created
android/jni/ # a folder
android/jni/Android.mk # a makefile containing
LOCAL_PATH := $(call my-dir)
LOCAL_MODULE := igalcon2
LOCAL_CFLAGS := #VARIOUS C FLAGS for define hacks
LOCAL_C_INCLUDES := #VARIOUS INCLUDE FOLDERS, RELATIVE TO android/jni/, so ../../src
LOCAL_SRC_FILES := #The c files, ../../src/whatever.c
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
android/default.properties # a file needed to build properly
this file must contain:
“target=android-4” for GLES
It instructs ndk-build which platform we’re using. Without it, the NDK can’t find the GLES headers.
Then I was able to run ndk-build while in the android folder and it started building my project.
Step 4 – OpenGL Includes:
I had to manage some various quirks in the C code and whatnot as I went.
The includes for GLES:
Step 5 – Installing a port of STL for the NDK:
Then I found that STL is not supported in the NDK. So I grabbed stlport from www.stlport.org .. Not needing iostream, etc myself, I just moved the stlport folder over so I could include templates from it. This gave endianess and compiler unrecognized type errors. Found this android specific STL port (should be patched into newer versions of stlport eventually.)
I had to add this to my CPPFLAGS: -D_STLP_USE_SIMPLE_NODE_ALLOC to avoid having it complain “stlport/stl/_alloc.h:210: undefined reference to `std::__node_alloc::_M_allocate(unsigned int&)”
From here it looks like a long way till I have a port working though. I need to get graphics rendering, touch input, keyboard input, music handling, and other little things that just make the game work. If anyone can give me tips on this tonight, feel free 🙂 I’m not excited about using JNI for all this. I’ve heard there are SDL ports, which I’m going to be considering. I also hear I’ve got to download all the game assets separately from the game itself, which seems painful. Time will tell on if this port will work out.