Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Seefried committed May 29, 2015
0 parents commit c066946
Show file tree
Hide file tree
Showing 436 changed files with 77,263 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build-vars.rc
bin/
obj/
44 changes: 44 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.declarative.games.epidemic.beta"
android:versionCode="6"
android:versionName="Build 6 (4976e9-47f861)"
android:installLocation="auto">

<!-- Create a Java class extending Activity and place it in a
directory under src matching the package, e.g.
src/com/gamemaker/game/MyGame.java
then replace "testglesActivity" with the name of your class (e.g. "MyGame")
in the XML below.
An example Java class can be found in README-android.txt
-->
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:allowBackup="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:hardwareAccelerated="true" >
<activity android:name="Activity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<!-- Android 2.3.3 -->
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="14" />

<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" android:required="true" />

<!-- Allow reading/writing to external storage -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Scripts to build Epidemic for Android

## Introduction

[Epidemic](https://github.com/sseefried/open-epidemic-game) is a game written for mobile
devices in Haskell.

This repo contains a script called `build-epidemic-apk.sh` to build the game for Android
devices using ARMv7 (or compatible) chipsets. The repo contains a thin Java wrapper that
calls into the natively compiled code of the game.

## Setting up a development environment

This won't just work out of the box. You will require a GHC cross compiler targetting
ARMv7 and will need to build all the associated libraries. This isn't straightforward at all!

However, I've done all the work for you with the help of Docker. Please see the repo
[`docker-epidemic-build-env`](https://github.com/sseefried/docker-epidemic-build-env.git)
for more details.

## Setting up the build script

You will need to create a file called `build-vars.rc`. See
[`build-vars-rc.example`](https://github.com/sseefried/android-build-epidemic-apk/blob/master/build-vars.rc.example)

You will need to set paths for:

* The [Epidemic](https://github.com/sseefried/open-epidemic-game) repo
* The Android NDK
* the directory containing static C libraries that Epidemic requires.

If you have used the `Dockerfile` in the repo
[`docker-epidemic-build-env`](https://github.com/sseefried/docker-epidemic-build-env.git)
(mentioned above), then you can just

cp build-vars.rc.example build-vars.rc


## Installing the APK on Android devices

Once you have run the build script you should find the file:

bin/com.declarative.games.epidemic.beta-debug.apk

You can install this file on your Android device with [`adb`](http://developer.android.com/tools/help/adb.html).

adb install -r com.declarative.games.epidemic.beta-debug.apk

On your device you will need to tick "Unknown Sources" in "Settings -> Security".
20 changes: 20 additions & 0 deletions ant.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is used to override default values used by the Ant build system.
#
# This file must be checked in Version Control Systems, as it is
# integral to the build system of your project.

# This file is only used by the Ant script.

# You can use this to override default values such as
# 'source.dir' for the location of your java source folder and
# 'out.dir' for the location of your output folder.

# You can also use it define how the release builds are signed by declaring
# the following properties:
# 'key.store' for the location of your keystore and
# 'key.alias' for the name of the key to use.
# The password will be asked during the build when you use the 'release' target.


key.store=/home/androidbuilder/keystore/declarative-games.keystore
key.alias=epidemic-beta
91 changes: 91 additions & 0 deletions build-epidemic-apk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
####################################################################################################

BUILD_VARS=$THIS_DIR/build-vars.rc
BUILD_VARS_BASE=$(basename $BUILD_VARS)
APK=com.declarative.games.epidemic.beta-release.apk
CABAL=arm-linux-androideabi-cabal
EPIDEMIC_C_LIBS="cairo cpufeatures freetype gmp iconv ogg pixman-1 png vorbis vorbisfile SDL2_mixer SDL2"

####################################################################################################

#
# Check for $BUILD_VARS file
#
if [ ! -f $BUILD_VARS ]; then
echo "You must create a file called $BUILD_VARS_BASE"
echo "See '$BUILD_VARS_BASE.example'"
exit 1
fi

source $BUILD_VARS

#
# Check for $CABAL
#
which $CABAL > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Could not find $CABAL"
exit 1
fi

if [ "$EPIDEMIC_REPO" = "" ]; then
echo
echo "$(basename $BUILD_VARS) does not defined EPIDEMIC_REPO variable."
echo "It must be set to the full path of the Epidemic game git repo."
exit 1
fi

if [ "$EPIDEMIC_C_LIB_DIR" = "" ]; then
echo
echo "$(basename $BUILD_VARS) does not defined EPIDEMIC_C_LIB_DIR variable."
echo "It must be set to the full path of the dir containing the following files: "
for i in $EPIDEMIC_C_LIBS; do
echo " lib$i.a"
done
exit 1
fi

for i in $EPIDEMIC_C_LIBS; do
if [ ! -f $EPIDEMIC_C_LIB_DIR/lib$i.a ]; then
echo "Could not find required library file 'lib$i.a'"
exit 1
fi
done

if [ "$NDK" = "" ]; then
echo
echo "$(basename $BUILD_VARS) does not defined NDK variable."
echo "It must be set to the Android NDK directory containing file 'ndk-build'"
exit 1
fi


cd $EPIDEMIC_REPO
$CABAL install -fandroid $@
[ $? -eq 0 ] || exit 1

cd $THIS_DIR

echo "[+] Copy across assets"
mkdir -p assets
cp $EPIDEMIC_REPO/assets/* assets

LIBS=`$THIS_DIR/resolve-libs arm-unknown-linux-androideabi-ghc-pkg Epidemic`
rm -rf libEpidemic.a
ar crsT libEpidemic.a $LIBS

TGT=jni/epidemic-libs/armeabi
mkdir -p $TGT


for i in $EPIDEMIC_C_LIBS; do
cp $EPIDEMIC_C_LIB_DIR/lib$i.a $TGT || exit 1
done

cp libEpidemic.a $TGT

$NDK/ndk-build clean && $NDK/ndk-build -j9 && ant debug
[ $? -eq 0 ] || exit 1
14 changes: 14 additions & 0 deletions build-vars.rc.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Path to Epidemic game repo
#
EPIDEMIC_REPO=$HOME/build/open-epidemic-game

#
# Path to Android NDK
#
NDK=$HOME/android-ndk-r9b

#
# Path to directory containing required static C libraries of Epidemic.
#
EPIDEMIC_C_LIB_DIR=$HOME/.ghc/android-14/arm-linux-androideabi-4.8/sysroot/usr/lib
93 changes: 93 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This should be changed to the name of your project -->
<project name="com.declarative.games.epidemic.beta" default="help">

<!-- The local.properties file is created and updated by the 'android' tool.
It contains the path to the SDK. It should *NOT* be checked into
Version Control Systems. -->
<property file="local.properties" />

<!-- The ant.properties file can be created by you. It is only edited by the
'android' tool to add properties to it.
This is the place to change some Ant specific build properties.
Here are some properties you may want to change/update:
source.dir
The name of the source directory. Default is 'src'.
out.dir
The name of the output directory. Default is 'bin'.
For other overridable properties, look at the beginning of the rules
files in the SDK, at tools/ant/build.xml
Properties related to the SDK location or the project target should
be updated using the 'android' tool with the 'update' action.
This file is an integral part of the build system for your
application and should be checked into Version Control Systems.
-->
<property file="ant.properties" />

<!-- if sdk.dir was not set from one of the property file, then
get it from the ANDROID_HOME env var.
This must be done before we load project.properties since
the proguard config can use sdk.dir -->
<property environment="env" />
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
<isset property="env.ANDROID_HOME" />
</condition>

<!-- The project.properties file is created and updated by the 'android'
tool, as well as ADT.
This contains project specific properties such as project target, and library
dependencies. Lower level build properties are stored in ant.properties
(or in .classpath for Eclipse projects).
This file is an integral part of the build system for your
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />

<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
unless="sdk.dir"
/>

<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />

<!-- Import the actual build file.
To customize existing targets, there are two options:
- Customize only one target:
- copy/paste the target into this file, *before* the
<import> task.
- customize it to your needs.
- Customize the whole content of build.xml
- copy/paste the content of the rules files (minus the top node)
into this file, replacing the <import> task.
- customize to your needs.
***********************
****** IMPORTANT ******
***********************
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
in order to avoid having your file be overridden by tools such as "android update project"
-->
<!-- version-tag: 1 -->
<import file="${sdk.dir}/tools/ant/build.xml" />

</project>
4 changes: 4 additions & 0 deletions custom_rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules" default="help">
<property file="secure.properties" />
</project>
11 changes: 11 additions & 0 deletions default.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-12
1 change: 1 addition & 0 deletions jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(call all-subdir-makefiles)
6 changes: 6 additions & 0 deletions jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Uncomment this if you're using STL in your project
# See CPLUSPLUS-SUPPORT.html in the NDK documentation for more information
# APP_STL := stlport_static

APP_ABI := armeabi
NDK_TOOLCHAIN := arm-linux-androideabi-4.8
46 changes: 46 additions & 0 deletions jni/epidemic-libs/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
LOCAL_PATH := $(call my-dir)

# The libmain that SDL enters

include $(CLEAR_VARS)
LOCAL_MODULE := main
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_SRC_FILES := src/SDL_android_main.c main.c

#
# sseefried:
# Even though the Android makefile infrastructure protests
# 'non-system libraries in linker flags' when you cram all
# the 'local static libraries' into LOCAL_LDLIBS I prefer
# this method since I can also pass the --start-group and
# --end-group linker flags meaning that the order in which
# the libraries are listed is not important. Working out
# the dependency order is not something I think I should have
# to do!
#

LOCAL_LDFLAGS += -Wl,--export-dynamic

LOCAL_LDLIBS := -L$(LOCAL_PATH)/$(TARGET_ARCH_ABI) \
-Wl,--start-group \
-llog \
-lEpidemic \
-lSDL2_mixer \
-lSDL2 \
-landroid \
-lGLESv1_CM \
-lGLESv2 \
-liconv \
-lvorbisfile \
-lvorbis \
-logg \
-lfreetype \
-lcairo \
-lpixman-1 \
-lpng \
-lz \
-lgmp \
-lcpufeatures \
-Wl,--end-group

include $(BUILD_SHARED_LIBRARY)
Loading

0 comments on commit c066946

Please sign in to comment.