build-scripts/androidbuild.sh
changeset 7793 6463a850229d
child 7907 24b4e98c6010
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build-scripts/androidbuild.sh	Wed Oct 09 10:29:01 2013 -0300
     1.3 @@ -0,0 +1,114 @@
     1.4 +#!/bin/bash
     1.5 +
     1.6 +SOURCES=()
     1.7 +MKSOURCES=""
     1.8 +CURDIR=`pwd -P`
     1.9 +
    1.10 +# Fetch sources
    1.11 +if [[ $# -ge 2 ]]; then
    1.12 +    for src in ${@:2}
    1.13 +    do
    1.14 +        SOURCES+=($src)
    1.15 +        MKSOURCES="$MKSOURCES $(basename $src)"
    1.16 +    done
    1.17 +else
    1.18 +    if [ -n "$1" ]; then
    1.19 +        while read src
    1.20 +        do
    1.21 +            SOURCES+=($src)
    1.22 +            MKSOURCES="$MKSOURCES $(basename $src)"
    1.23 +        done
    1.24 +    fi
    1.25 +fi
    1.26 +
    1.27 +if [ -z "$1" ] || [ -z "$SOURCES" ]; then
    1.28 +    echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
    1.29 +    echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
    1.30 +    exit 1
    1.31 +fi
    1.32 +
    1.33 +
    1.34 +
    1.35 +SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
    1.36 +
    1.37 +NDKBUILD=`which ndk-build`
    1.38 +if [ -z "$NDKBUILD" ];then
    1.39 +    echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
    1.40 +    exit 1
    1.41 +fi
    1.42 +
    1.43 +ANDROID=`which android`
    1.44 +if [ -z "$ANDROID" ];then
    1.45 +    echo "Could not find the android utility, install Android's SDK and add it to the path"
    1.46 +    exit 1
    1.47 +fi
    1.48 +
    1.49 +ANT=`which ant`
    1.50 +
    1.51 +if [ -z "$ANT" ];then
    1.52 +    echo "Could not find the ant utility, install Android's SDK and add it to the path"
    1.53 +    exit 1
    1.54 +fi
    1.55 +
    1.56 +APP="$1"
    1.57 +APPARR=(${APP//./ })
    1.58 +BUILDPATH="$SDLPATH/build/$APP"
    1.59 +
    1.60 +# Start Building
    1.61 +
    1.62 +rm -rf $BUILDPATH
    1.63 +mkdir -p $BUILDPATH
    1.64 +
    1.65 +cp -r $SDLPATH/android-project/* $BUILDPATH
    1.66 +
    1.67 +# Copy SDL sources
    1.68 +mkdir -p $BUILDPATH/jni/SDL
    1.69 +cp -r $SDLPATH/src $BUILDPATH/jni/SDL
    1.70 +cp -r $SDLPATH/include $BUILDPATH/jni/SDL
    1.71 +cp $SDLPATH/Android.mk $BUILDPATH/jni/SDL
    1.72 +sed -i "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/jni/src/Android.mk
    1.73 +sed -i "s|org\.libsdl\.app|$APP|g" $BUILDPATH/AndroidManifest.xml
    1.74 +
    1.75 +# Copy user sources
    1.76 +for src in "${SOURCES[@]}"
    1.77 +do
    1.78 +    cp $src $BUILDPATH/jni/src
    1.79 +done
    1.80 +
    1.81 +# Create an inherited Activity
    1.82 +cd $BUILDPATH/src
    1.83 +for folder in "${APPARR[@]}"
    1.84 +do
    1.85 +    mkdir -p $folder
    1.86 +    cd $folder
    1.87 +done
    1.88 +
    1.89 +ACTIVITY="${folder}Activity"
    1.90 +sed -i "s|SDLActivity|$ACTIVITY|g" $BUILDPATH/AndroidManifest.xml
    1.91 +sed -i "s|SDLActivity|$APP|g" $BUILDPATH/build.xml
    1.92 +
    1.93 +# Fill in a default Activity
    1.94 +echo "package $APP;" >  "$ACTIVITY.java"
    1.95 +echo "import org.libsdl.app.SDLActivity;" >> "$ACTIVITY.java"
    1.96 +echo "public class $ACTIVITY extends SDLActivity {}" >> "$ACTIVITY.java"
    1.97 +
    1.98 +# Update project and build
    1.99 +cd $BUILDPATH
   1.100 +android update project --path $BUILDPATH
   1.101 +$NDKBUILD
   1.102 +$ANT debug
   1.103 +
   1.104 +cd $CURDIR
   1.105 +
   1.106 +APK="$BUILDPATH/bin/$APP-debug.apk"
   1.107 +
   1.108 +if [ -f "$APK" ]; then
   1.109 +    echo "Your APK is ready at $APK"
   1.110 +    echo "To install to your device: "
   1.111 +    echo "cd  $BUILDPATH"
   1.112 +    echo "ant debug install"
   1.113 +    exit 0
   1.114 +fi
   1.115 +
   1.116 +echo "There was an error building the APK"
   1.117 +exit 1
   1.118 \ No newline at end of file