Compiling Doom with NDK


Build your own Android App Dev Empire

Get Instant Access

If you read this book carefully, you'll get the sense that that I don't like the NDK 1.5 (when I started in this project the NDK didn't even exist). I think the NDK 1.5 is cumbersome to use, because of the lack of integration with the Eclipse workbench. Plus, version 1.5 has only the bare bones to compile a native library (that is, the C runtime, Compression library, and basic C++ support). Just when this book was being finished up, Google released the NDK 1.6, a nice improvement over 1.5. Here are the highlights of this new version:

• The sources folder from the NDK folder structure is gone (see the section on Wolf 3D and NDK 1.5). Now, all code (Java and native) lives in the apps folder. Within the apps folder, the project folder contains the Android Java project, and within project, the jni folder contains the native code and the Makefile

• NDK 1.6 adds support for OpenGL ES 2.0. This welcome addition will help many 3D games out there.

I would recommend the NDK over the CodeSourcery G++ compiler if you have a slow system such as a laptop or VMware combination or if your library crashes mysteriously, perhaps because of GNU compiler version issues, which can happen in programs that are not highly portable. Discrepancies in the GNU compiler version (for example, CodeSourcery uses GCC 4.3.x instead of Android's 4.2.x) can cause optimization errors and other types of runtime errors that ultimately crash the game.

All in all, NDK 1.6 is a good improvement but still has far to go to catch up with other powerful tools, such as Apple's iPhone Xcode platform. For example, the NDK will recompile the entire library if you change the Makefile, Android .mk (too add a new source file for example). This is really annoying when you have a big library with lots of source files. Other tools such as GNU make will detect the changes and recompile only the right files in the library. Anyway, for Doom, the folder structure for NDK 1.6 should look as follows:

• android-ndk-1.6_r1/apps/Doom/ This file defines the module name to be built.

• android-ndk-1.6_r1/apps/Doom/project: This folder contains the actual Android project for the game.

• android-ndk-1.6_r1/apps/Doom/project/jni: This folder contains the native code and the Makefile,

Here is how you get Doom to compile with NDK 1.6:

1. Create android-ndk-1.6_r1/apps/Doom/ This file contains the module (doom) that we are building:

APP_PROJJECT_PATH := $(call my-dir)/project APP_MODULES := doom

2. Create the folder android-ndk-1.6_r1/apps/Doom/project. Copy the Android project from ch07.Android.Doom to this folder. You don't need to copy the native folder (this is the native code).

3. Create the folder android-ndk-1.6_r1/apps/Doom/project/jni, and copy the native code from ch07.Android.Doom/native/prboom.

4. Create a Makefile called in android-ndk-1.6_r1/apps/Doom/ project/jni. This make file should look as follows:

# clear vars include $(CLEAR_VARS)

# module name LOCAL MODULE := doom

# doom folder

DOOM := apps/Doom/project/jni

# includes



OPTS := -O3 -ffast-math -fexpensive-optimizations LOCALJCFLAGS := $(DOOM_FLAGS) $(OPTS) $(INC)


m_cheat.c md5.c am_map.c hu_lib.c djdeh.c djitems.c d_main.c doomdef.c doomstat.c PjChecksum.c dstrings.c fjfinale.c fjWipe.c gjgame.c m_bbox.c d client.c

lights.c p_user.c sounds.c \ p_map.c r_bsp.c s_sound.c \ hu_stuff.c m_menu.c p_maputl.c r_data.c st_lib.c \

m_misc.c p_mobj.c r_demo.c st_stuff.c \ info.c p_plats.c r_draw.c tables.c \

m_random.c p_pspr.c r_filter.c version.c \ PjCeilng.c p_saveg.c r_fps.c v video.c \ p_setup.c r_main.c Pjdoors.c p_sight.c p_enemy.c p_spec.c r_plane.c p_switch.c Pjtelept.c r_things.c

Pjfloor.c Pjgenlin.c Pjtick.c wi_stuff.c \ r_patch.c w_memcache.c w_mmap.c r_segs.c r_sky.c z zone.c \

lprintf.c m_argv.c p_inter.c d_server.c \

droid/i_video.c droid/i_network.c droid/i_joy.c \ droid/i_system.c droid/i_main.c droid/i_sound.c \ droid/jni_doom.c

# Build include $(BUILD_SHARED_LIBRARY)

5. Finally, run make APP=Doom from the NDK root folder android-ndk-1.6_r1. The output library will be stored in Doom/project//libs/armeabi and ready to use. Import Doom/project into your Eclipse workspace, and start the game.

Was this article helpful?

0 0

Post a comment