build-scripts/androidbuild.sh
changeset 11647 5816b27073a4
parent 10200 c678dcec4f44
child 11649 fe6769530709
equal deleted inserted replaced
11646:c875be618b90 11647:5816b27073a4
    31 
    31 
    32 
    32 
    33 
    33 
    34 SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
    34 SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
    35 
    35 
       
    36 if [ -z "$ANDROID_HOME" ];then
       
    37     echo "Please set the ANDROID_HOME directory to the path of the Android SDK"
       
    38     exit 1
       
    39 fi
       
    40 
    36 NDKBUILD=`which ndk-build`
    41 NDKBUILD=`which ndk-build`
    37 if [ -z "$NDKBUILD" ];then
    42 if [ -z "$NDKBUILD" ];then
    38     echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
    43     echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
    39     exit 1
    44     exit 1
    40 fi
    45 fi
    41 
    46 
    42 ANDROID=`which android`
    47 ANDROID="$ANDROID_HOME/tools/android"
       
    48 if [ ! -f "$ANDROID" ]; then
       
    49     ANDROID=`which android`
       
    50 fi
    43 if [ -z "$ANDROID" ];then
    51 if [ -z "$ANDROID" ];then
    44     echo "Could not find the android utility, install Android's SDK and add it to the path"
    52     echo "Could not find the android utility, install Android's SDK and add it to the path"
    45     exit 1
       
    46 fi
       
    47 
       
    48 ANT=`which ant`
       
    49 
       
    50 if [ -z "$ANT" ];then
       
    51     echo "Could not find the ant utility, install Android's SDK and add it to the path"
       
    52     exit 1
    53     exit 1
    53 fi
    54 fi
    54 
    55 
    55 NCPUS="1"
    56 NCPUS="1"
    56 case "$OSTYPE" in
    57 case "$OSTYPE" in
    75 mkdir -p $BUILDPATH
    76 mkdir -p $BUILDPATH
    76 
    77 
    77 cp -r $SDLPATH/android-project/* $BUILDPATH
    78 cp -r $SDLPATH/android-project/* $BUILDPATH
    78 
    79 
    79 # Copy SDL sources
    80 # Copy SDL sources
    80 mkdir -p $BUILDPATH/jni/SDL
    81 mkdir -p $BUILDPATH/app/jni/SDL
    81 if [ -z "$COPYSOURCE" ]; then
    82 if [ -z "$COPYSOURCE" ]; then
    82     ln -s $SDLPATH/src $BUILDPATH/jni/SDL
    83     ln -s $SDLPATH/src $BUILDPATH/app/jni/SDL
    83     ln -s $SDLPATH/include $BUILDPATH/jni/SDL
    84     ln -s $SDLPATH/include $BUILDPATH/app/jni/SDL
    84 else
    85 else
    85     cp -r $SDLPATH/src $BUILDPATH/jni/SDL
    86     cp -r $SDLPATH/src $BUILDPATH/app/jni/SDL
    86     cp -r $SDLPATH/include $BUILDPATH/jni/SDL
    87     cp -r $SDLPATH/include $BUILDPATH/app/jni/SDL
    87 fi
    88 fi
    88 
    89 
    89 cp -r $SDLPATH/Android.mk $BUILDPATH/jni/SDL
    90 cp -r $SDLPATH/Android.mk $BUILDPATH/app/jni/SDL
    90 sed -i -e "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/jni/src/Android.mk
    91 sed -i -e "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/app/jni/src/Android.mk
    91 sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/AndroidManifest.xml
    92 sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/app/build.gradle
       
    93 sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/app/src/main/AndroidManifest.xml
    92 
    94 
    93 # Copy user sources
    95 # Copy user sources
    94 for src in "${SOURCES[@]}"
    96 for src in "${SOURCES[@]}"
    95 do
    97 do
    96     cp $src $BUILDPATH/jni/src
    98     cp $src $BUILDPATH/app/jni/src
    97 done
    99 done
    98 
   100 
    99 # Create an inherited Activity
   101 # Create an inherited Activity
   100 cd $BUILDPATH/src
   102 cd $BUILDPATH/app/src/main/java
   101 for folder in "${APPARR[@]}"
   103 for folder in "${APPARR[@]}"
   102 do
   104 do
   103     mkdir -p $folder
   105     mkdir -p $folder
   104     cd $folder
   106     cd $folder
   105 done
   107 done
   106 
   108 
   107 ACTIVITY="${folder}Activity"
   109 ACTIVITY="${folder}Activity"
   108 sed -i -e "s|SDLActivity|$ACTIVITY|g" $BUILDPATH/AndroidManifest.xml
   110 sed -i -e "s|\"SDLActivity\"|\"$ACTIVITY\"|g" $BUILDPATH/app/src/main/AndroidManifest.xml
   109 sed -i -e "s|SDLActivity|$APP|g" $BUILDPATH/build.xml
       
   110 
   111 
   111 # Fill in a default Activity
   112 # Fill in a default Activity
   112 echo "package $APP;" >  "$ACTIVITY.java"
   113 cat >"$ACTIVITY.java" <<__EOF__
   113 echo "import org.libsdl.app.SDLActivity;" >> "$ACTIVITY.java"
   114 package $APP;
   114 echo "public class $ACTIVITY extends SDLActivity {}" >> "$ACTIVITY.java"
   115 
       
   116 import org.libsdl.app.SDLActivity;
       
   117 
       
   118 public class $ACTIVITY extends SDLActivity
       
   119 {
       
   120 }
       
   121 __EOF__
   115 
   122 
   116 # Update project and build
   123 # Update project and build
   117 cd $BUILDPATH
   124 cd $BUILDPATH
   118 $ANDROID update project --path $BUILDPATH
   125 pushd $BUILDPATH/app/jni
   119 $NDKBUILD -j $NCPUS $NDKARGS
   126 $NDKBUILD -j $NCPUS $NDKARGS
   120 $ANT debug
   127 popd
       
   128 
       
   129 # Start gradle build
       
   130 $BUILDPATH/gradlew build
   121 
   131 
   122 cd $CURDIR
   132 cd $CURDIR
   123 
   133 
   124 APK="$BUILDPATH/bin/$APP-debug.apk"
   134 APK="$BUILDPATH/app/build/outputs/apk/app-debug.apk"
   125 
   135 
   126 if [ -f "$APK" ]; then
   136 if [ -f "$APK" ]; then
   127     echo "Your APK is ready at $APK"
   137     echo "Your APK is ready at $APK"
   128     echo "To install to your device: "
   138     echo "To install to your device: "
   129     echo "cd  $BUILDPATH"
   139     echo "$ANDROID_HOME/platform-tools/adb install -r $APK"
   130     echo "ant debug install"
       
   131     exit 0
   140     exit 0
   132 fi
   141 fi
   133 
   142 
   134 echo "There was an error building the APK"
   143 echo "There was an error building the APK"
   135 exit 1
   144 exit 1