Game Development Reference
In-Depth Information
Linking and source code organization
In the previous recipes, we learned how to create basic wrappers that allow us to run our
application on Android and Windows. However, we used an ad-hoc approach since the amount
of source code was low and it into a single ile. We have to organize our project source iles in
a way suitable for building the code for larger projects in Windows and Android.
Getting ready
Recall the folder structure of the
App3
project. We have the
src
and
jni
folders inside our
App2
folder. The
jni/Android.mk
,
jni/Application.mk
, and
build.xml
iles specify
the Android build process. To enable the Windows executable creation, we add a ile named
Makefile
, which references the
main.cpp
ile.
How to do it...
The following is the content of
Makefile
:
CC = gcc
all:
$(CC) -o main.exe main.cpp -lgdi32 -lstdc++
The idea is that when we add more and more OS-independent logic, the code resides in
.cpp
iles, which do not reference any OS-speciic headers or libraries. For the irst few chapters,
this simple framework that delegates frame rendering and event handling to portable OS-
independent functions (
OnDrawFrame()
,
OnKeyUp()
and so on) is enough.
How it works...
All of our examples from the subsequent chapters are buildable for Windows from the
command line using a single
make all
command. Android native code is buildable with a
single
ndk-build
command. We will use this convention throughout the rest of the topic.
Signing release Android applications
Now we can create a cross-platform application, debug it on a PC, and deploy it to Android
devices. We cannot, however, upload it on Google Play because it is not (yet) signed properly
with the release key.