Adds test framework to Android.mk and a simple utility to build Android projects

Gabriel Jacobo 2013-10-09 10:29:01 -03:00
parent c455f7291c
commit 24f237710f
3 changed files with 143 additions and 2 deletions

View File

@ -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

View File

@ -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

114
build-scripts/androidbuild.sh Executable file
View File

@ -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