Adds test framework to Android.mk and a simple utility to build Android projects
authorGabriel Jacobo <gabomdq@gmail.com>
Wed, 09 Oct 2013 10:29:01 -0300
changeset 77936463a850229d
parent 7792 b8d4be87970a
child 7794 7995e0920bf9
Adds test framework to Android.mk and a simple utility to build Android projects
Android.mk
README-android.txt
build-scripts/androidbuild.sh
     1.1 --- a/Android.mk	Mon Oct 07 14:16:38 2013 -0700
     1.2 +++ b/Android.mk	Wed Oct 09 10:29:01 2013 -0300
     1.3 @@ -42,7 +42,8 @@
     1.4  	$(wildcard $(LOCAL_PATH)/src/timer/*.c) \
     1.5  	$(wildcard $(LOCAL_PATH)/src/timer/unix/*.c) \
     1.6  	$(wildcard $(LOCAL_PATH)/src/video/*.c) \
     1.7 -	$(wildcard $(LOCAL_PATH)/src/video/android/*.c))
     1.8 +	$(wildcard $(LOCAL_PATH)/src/video/android/*.c) \
     1.9 +    $(wildcard $(LOCAL_PATH)/src/test/*.c))
    1.10  
    1.11  LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES
    1.12  LOCAL_LDLIBS := -ldl -lGLESv1_CM -lGLESv2 -llog -landroid
     2.1 --- a/README-android.txt	Mon Oct 07 14:16:38 2013 -0700
     2.2 +++ b/README-android.txt	Wed Oct 09 10:29:01 2013 -0300
     2.3 @@ -38,7 +38,33 @@
     2.4   Building an app
     2.5  ================================================================================
     2.6  
     2.7 -Instructions:
     2.8 +For simple projects you can use the script located at build-scripts/androidbuild.sh
     2.9 +
    2.10 +There's two ways of using it:
    2.11 +
    2.12 +androidbuild.sh com.yourcompany.yourapp < sources.list
    2.13 +androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c
    2.14 +
    2.15 +sources.list should be a text file with a source file name in each line
    2.16 +Filenames should be specified relative to the current directory, for example if
    2.17 +you are in the build-scripts directory and want to create the testgles.c test, you'll
    2.18 +run:
    2.19 +    
    2.20 +./androidbuild.sh org.libsdl.testgles ../test/testgles.c
    2.21 +
    2.22 +One limitation of this script is that all sources provided will be aggregated into
    2.23 +a single directory, thus all your source files should have a unique name.
    2.24 +
    2.25 +Once the project is complete the script will tell you where the debug APK is located.
    2.26 +If you want to create a signed release APK, you can use the project created by this
    2.27 +utility to generate it.
    2.28 +
    2.29 +Finally, a word of caution: re running androidbuild.sh wipes any changes you may have
    2.30 +done in the build directory for the app!
    2.31 +
    2.32 +
    2.33 +For more complex projects, follow these instructions:
    2.34 +    
    2.35  1. Copy the android-project directory wherever you want to keep your projects
    2.36     and rename it to the name of your project.
    2.37  2. Move or symlink this SDL directory into the <project>/jni directory
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/build-scripts/androidbuild.sh	Wed Oct 09 10:29:01 2013 -0300
     3.3 @@ -0,0 +1,114 @@
     3.4 +#!/bin/bash
     3.5 +
     3.6 +SOURCES=()
     3.7 +MKSOURCES=""
     3.8 +CURDIR=`pwd -P`
     3.9 +
    3.10 +# Fetch sources
    3.11 +if [[ $# -ge 2 ]]; then
    3.12 +    for src in ${@:2}
    3.13 +    do
    3.14 +        SOURCES+=($src)
    3.15 +        MKSOURCES="$MKSOURCES $(basename $src)"
    3.16 +    done
    3.17 +else
    3.18 +    if [ -n "$1" ]; then
    3.19 +        while read src
    3.20 +        do
    3.21 +            SOURCES+=($src)
    3.22 +            MKSOURCES="$MKSOURCES $(basename $src)"
    3.23 +        done
    3.24 +    fi
    3.25 +fi
    3.26 +
    3.27 +if [ -z "$1" ] || [ -z "$SOURCES" ]; then
    3.28 +    echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
    3.29 +    echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
    3.30 +    exit 1
    3.31 +fi
    3.32 +
    3.33 +
    3.34 +
    3.35 +SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
    3.36 +
    3.37 +NDKBUILD=`which ndk-build`
    3.38 +if [ -z "$NDKBUILD" ];then
    3.39 +    echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
    3.40 +    exit 1
    3.41 +fi
    3.42 +
    3.43 +ANDROID=`which android`
    3.44 +if [ -z "$ANDROID" ];then
    3.45 +    echo "Could not find the android utility, install Android's SDK and add it to the path"
    3.46 +    exit 1
    3.47 +fi
    3.48 +
    3.49 +ANT=`which ant`
    3.50 +
    3.51 +if [ -z "$ANT" ];then
    3.52 +    echo "Could not find the ant utility, install Android's SDK and add it to the path"
    3.53 +    exit 1
    3.54 +fi
    3.55 +
    3.56 +APP="$1"
    3.57 +APPARR=(${APP//./ })
    3.58 +BUILDPATH="$SDLPATH/build/$APP"
    3.59 +
    3.60 +# Start Building
    3.61 +
    3.62 +rm -rf $BUILDPATH
    3.63 +mkdir -p $BUILDPATH
    3.64 +
    3.65 +cp -r $SDLPATH/android-project/* $BUILDPATH
    3.66 +
    3.67 +# Copy SDL sources
    3.68 +mkdir -p $BUILDPATH/jni/SDL
    3.69 +cp -r $SDLPATH/src $BUILDPATH/jni/SDL
    3.70 +cp -r $SDLPATH/include $BUILDPATH/jni/SDL
    3.71 +cp $SDLPATH/Android.mk $BUILDPATH/jni/SDL
    3.72 +sed -i "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/jni/src/Android.mk
    3.73 +sed -i "s|org\.libsdl\.app|$APP|g" $BUILDPATH/AndroidManifest.xml
    3.74 +
    3.75 +# Copy user sources
    3.76 +for src in "${SOURCES[@]}"
    3.77 +do
    3.78 +    cp $src $BUILDPATH/jni/src
    3.79 +done
    3.80 +
    3.81 +# Create an inherited Activity
    3.82 +cd $BUILDPATH/src
    3.83 +for folder in "${APPARR[@]}"
    3.84 +do
    3.85 +    mkdir -p $folder
    3.86 +    cd $folder
    3.87 +done
    3.88 +
    3.89 +ACTIVITY="${folder}Activity"
    3.90 +sed -i "s|SDLActivity|$ACTIVITY|g" $BUILDPATH/AndroidManifest.xml
    3.91 +sed -i "s|SDLActivity|$APP|g" $BUILDPATH/build.xml
    3.92 +
    3.93 +# Fill in a default Activity
    3.94 +echo "package $APP;" >  "$ACTIVITY.java"
    3.95 +echo "import org.libsdl.app.SDLActivity;" >> "$ACTIVITY.java"
    3.96 +echo "public class $ACTIVITY extends SDLActivity {}" >> "$ACTIVITY.java"
    3.97 +
    3.98 +# Update project and build
    3.99 +cd $BUILDPATH
   3.100 +android update project --path $BUILDPATH
   3.101 +$NDKBUILD
   3.102 +$ANT debug
   3.103 +
   3.104 +cd $CURDIR
   3.105 +
   3.106 +APK="$BUILDPATH/bin/$APP-debug.apk"
   3.107 +
   3.108 +if [ -f "$APK" ]; then
   3.109 +    echo "Your APK is ready at $APK"
   3.110 +    echo "To install to your device: "
   3.111 +    echo "cd  $BUILDPATH"
   3.112 +    echo "ant debug install"
   3.113 +    exit 0
   3.114 +fi
   3.115 +
   3.116 +echo "There was an error building the APK"
   3.117 +exit 1
   3.118 \ No newline at end of file