Adds test framework to Android.mk and a simple utility to build Android projects
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
diff --git a/Android.mk b/Android.mk
index f3fcb3a..3cb1e31 100755
--- a/Android.mk
+++ b/Android.mk
@@ -42,7 +42,8 @@ LOCAL_SRC_FILES := \
$(wildcard $(LOCAL_PATH)/src/timer/*.c) \
$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \
$(wildcard $(LOCAL_PATH)/src/video/*.c) \
- $(wildcard $(LOCAL_PATH)/src/video/android/*.c))
+ $(wildcard $(LOCAL_PATH)/src/video/android/*.c) \
+ $(wildcard $(LOCAL_PATH)/src/test/*.c))
LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES
LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog -landroid
diff --git a/README-android.txt b/README-android.txt
index ecd31ae..adf3f64 100644
--- a/README-android.txt
+++ b/README-android.txt
@@ -38,7 +38,33 @@ src/main/android/SDL_android_main.c
Building an app
================================================================================
-Instructions:
+For simple projects you can use the script located at build-scripts/androidbuild.sh
+
+There's two ways of using it:
+
+androidbuild.sh com.yourcompany.yourapp < sources.list
+androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c
+
+sources.list should be a text file with a source file name in each line
+Filenames should be specified relative to the current directory, for example if
+you are in the build-scripts directory and want to create the testgles.c test, you'll
+run:
+
+./androidbuild.sh org.libsdl.testgles ../test/testgles.c
+
+One limitation of this script is that all sources provided will be aggregated into
+a single directory, thus all your source files should have a unique name.
+
+Once the project is complete the script will tell you where the debug APK is located.
+If you want to create a signed release APK, you can use the project created by this
+utility to generate it.
+
+Finally, a word of caution: re running androidbuild.sh wipes any changes you may have
+done in the build directory for the app!
+
+
+For more complex projects, follow these instructions:
+
1. Copy the android-project directory wherever you want to keep your projects
and rename it to the name of your project.
2. Move or symlink this SDL directory into the <project>/jni directory
diff --git a/build-scripts/androidbuild.sh b/build-scripts/androidbuild.sh
new file mode 100755
index 0000000..b4a8323
--- /dev/null
+++ b/build-scripts/androidbuild.sh
@@ -0,0 +1,114 @@
+#!/bin/bash
+
+SOURCES=()
+MKSOURCES=""
+CURDIR=`pwd -P`
+
+# Fetch sources
+if [[ $# -ge 2 ]]; then
+ for src in ${@:2}
+ do
+ SOURCES+=($src)
+ MKSOURCES="$MKSOURCES $(basename $src)"
+ done
+else
+ if [ -n "$1" ]; then
+ while read src
+ do
+ SOURCES+=($src)
+ MKSOURCES="$MKSOURCES $(basename $src)"
+ done
+ fi
+fi
+
+if [ -z "$1" ] || [ -z "$SOURCES" ]; then
+ echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
+ echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
+ exit 1
+fi
+
+
+
+SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
+
+NDKBUILD=`which ndk-build`
+if [ -z "$NDKBUILD" ];then
+ echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
+ exit 1
+fi
+
+ANDROID=`which android`
+if [ -z "$ANDROID" ];then
+ echo "Could not find the android utility, install Android's SDK and add it to the path"
+ exit 1
+fi
+
+ANT=`which ant`
+
+if [ -z "$ANT" ];then
+ echo "Could not find the ant utility, install Android's SDK and add it to the path"
+ exit 1
+fi
+
+APP="$1"
+APPARR=(${APP//./ })
+BUILDPATH="$SDLPATH/build/$APP"
+
+# Start Building
+
+rm -rf $BUILDPATH
+mkdir -p $BUILDPATH
+
+cp -r $SDLPATH/android-project/* $BUILDPATH
+
+# Copy SDL sources
+mkdir -p $BUILDPATH/jni/SDL
+cp -r $SDLPATH/src $BUILDPATH/jni/SDL
+cp -r $SDLPATH/include $BUILDPATH/jni/SDL
+cp $SDLPATH/Android.mk $BUILDPATH/jni/SDL
+sed -i "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/jni/src/Android.mk
+sed -i "s|org\.libsdl\.app|$APP|g" $BUILDPATH/AndroidManifest.xml
+
+# Copy user sources
+for src in "${SOURCES[@]}"
+do
+ cp $src $BUILDPATH/jni/src
+done
+
+# Create an inherited Activity
+cd $BUILDPATH/src
+for folder in "${APPARR[@]}"
+do
+ mkdir -p $folder
+ cd $folder
+done
+
+ACTIVITY="${folder}Activity"
+sed -i "s|SDLActivity|$ACTIVITY|g" $BUILDPATH/AndroidManifest.xml
+sed -i "s|SDLActivity|$APP|g" $BUILDPATH/build.xml
+
+# Fill in a default Activity
+echo "package $APP;" > "$ACTIVITY.java"
+echo "import org.libsdl.app.SDLActivity;" >> "$ACTIVITY.java"
+echo "public class $ACTIVITY extends SDLActivity {}" >> "$ACTIVITY.java"
+
+# Update project and build
+cd $BUILDPATH
+android update project --path $BUILDPATH
+$NDKBUILD
+$ANT debug
+
+cd $CURDIR
+
+APK="$BUILDPATH/bin/$APP-debug.apk"
+
+if [ -f "$APK" ]; then
+ echo "Your APK is ready at $APK"
+ echo "To install to your device: "
+ echo "cd $BUILDPATH"
+ echo "ant debug install"
+ exit 0
+fi
+
+echo "There was an error building the APK"
+exit 1
\ No newline at end of file