build-scripts/androidbuild.sh
changeset 11647 5816b27073a4
parent 10200 c678dcec4f44
child 11649 fe6769530709
     1.1 --- a/build-scripts/androidbuild.sh	Mon Oct 23 12:33:18 2017 -0700
     1.2 +++ b/build-scripts/androidbuild.sh	Mon Oct 23 15:23:43 2017 -0700
     1.3 @@ -33,25 +33,26 @@
     1.4  
     1.5  SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
     1.6  
     1.7 +if [ -z "$ANDROID_HOME" ];then
     1.8 +    echo "Please set the ANDROID_HOME directory to the path of the Android SDK"
     1.9 +    exit 1
    1.10 +fi
    1.11 +
    1.12  NDKBUILD=`which ndk-build`
    1.13  if [ -z "$NDKBUILD" ];then
    1.14      echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
    1.15      exit 1
    1.16  fi
    1.17  
    1.18 -ANDROID=`which android`
    1.19 +ANDROID="$ANDROID_HOME/tools/android"
    1.20 +if [ ! -f "$ANDROID" ]; then
    1.21 +    ANDROID=`which android`
    1.22 +fi
    1.23  if [ -z "$ANDROID" ];then
    1.24      echo "Could not find the android utility, install Android's SDK and add it to the path"
    1.25      exit 1
    1.26  fi
    1.27  
    1.28 -ANT=`which ant`
    1.29 -
    1.30 -if [ -z "$ANT" ];then
    1.31 -    echo "Could not find the ant utility, install Android's SDK and add it to the path"
    1.32 -    exit 1
    1.33 -fi
    1.34 -
    1.35  NCPUS="1"
    1.36  case "$OSTYPE" in
    1.37      darwin*)
    1.38 @@ -77,27 +78,28 @@
    1.39  cp -r $SDLPATH/android-project/* $BUILDPATH
    1.40  
    1.41  # Copy SDL sources
    1.42 -mkdir -p $BUILDPATH/jni/SDL
    1.43 +mkdir -p $BUILDPATH/app/jni/SDL
    1.44  if [ -z "$COPYSOURCE" ]; then
    1.45 -    ln -s $SDLPATH/src $BUILDPATH/jni/SDL
    1.46 -    ln -s $SDLPATH/include $BUILDPATH/jni/SDL
    1.47 +    ln -s $SDLPATH/src $BUILDPATH/app/jni/SDL
    1.48 +    ln -s $SDLPATH/include $BUILDPATH/app/jni/SDL
    1.49  else
    1.50 -    cp -r $SDLPATH/src $BUILDPATH/jni/SDL
    1.51 -    cp -r $SDLPATH/include $BUILDPATH/jni/SDL
    1.52 +    cp -r $SDLPATH/src $BUILDPATH/app/jni/SDL
    1.53 +    cp -r $SDLPATH/include $BUILDPATH/app/jni/SDL
    1.54  fi
    1.55  
    1.56 -cp -r $SDLPATH/Android.mk $BUILDPATH/jni/SDL
    1.57 -sed -i -e "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/jni/src/Android.mk
    1.58 -sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/AndroidManifest.xml
    1.59 +cp -r $SDLPATH/Android.mk $BUILDPATH/app/jni/SDL
    1.60 +sed -i -e "s|YourSourceHere.c|$MKSOURCES|g" $BUILDPATH/app/jni/src/Android.mk
    1.61 +sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/app/build.gradle
    1.62 +sed -i -e "s|org\.libsdl\.app|$APP|g" $BUILDPATH/app/src/main/AndroidManifest.xml
    1.63  
    1.64  # Copy user sources
    1.65  for src in "${SOURCES[@]}"
    1.66  do
    1.67 -    cp $src $BUILDPATH/jni/src
    1.68 +    cp $src $BUILDPATH/app/jni/src
    1.69  done
    1.70  
    1.71  # Create an inherited Activity
    1.72 -cd $BUILDPATH/src
    1.73 +cd $BUILDPATH/app/src/main/java
    1.74  for folder in "${APPARR[@]}"
    1.75  do
    1.76      mkdir -p $folder
    1.77 @@ -105,31 +107,38 @@
    1.78  done
    1.79  
    1.80  ACTIVITY="${folder}Activity"
    1.81 -sed -i -e "s|SDLActivity|$ACTIVITY|g" $BUILDPATH/AndroidManifest.xml
    1.82 -sed -i -e "s|SDLActivity|$APP|g" $BUILDPATH/build.xml
    1.83 +sed -i -e "s|\"SDLActivity\"|\"$ACTIVITY\"|g" $BUILDPATH/app/src/main/AndroidManifest.xml
    1.84  
    1.85  # Fill in a default Activity
    1.86 -echo "package $APP;" >  "$ACTIVITY.java"
    1.87 -echo "import org.libsdl.app.SDLActivity;" >> "$ACTIVITY.java"
    1.88 -echo "public class $ACTIVITY extends SDLActivity {}" >> "$ACTIVITY.java"
    1.89 +cat >"$ACTIVITY.java" <<__EOF__
    1.90 +package $APP;
    1.91 +
    1.92 +import org.libsdl.app.SDLActivity;
    1.93 +
    1.94 +public class $ACTIVITY extends SDLActivity
    1.95 +{
    1.96 +}
    1.97 +__EOF__
    1.98  
    1.99  # Update project and build
   1.100  cd $BUILDPATH
   1.101 -$ANDROID update project --path $BUILDPATH
   1.102 +pushd $BUILDPATH/app/jni
   1.103  $NDKBUILD -j $NCPUS $NDKARGS
   1.104 -$ANT debug
   1.105 +popd
   1.106 +
   1.107 +# Start gradle build
   1.108 +$BUILDPATH/gradlew build
   1.109  
   1.110  cd $CURDIR
   1.111  
   1.112 -APK="$BUILDPATH/bin/$APP-debug.apk"
   1.113 +APK="$BUILDPATH/app/build/outputs/apk/app-debug.apk"
   1.114  
   1.115  if [ -f "$APK" ]; then
   1.116      echo "Your APK is ready at $APK"
   1.117      echo "To install to your device: "
   1.118 -    echo "cd  $BUILDPATH"
   1.119 -    echo "ant debug install"
   1.120 +    echo "$ANDROID_HOME/platform-tools/adb install -r $APK"
   1.121      exit 0
   1.122  fi
   1.123  
   1.124  echo "There was an error building the APK"
   1.125 -exit 1
   1.126 \ No newline at end of file
   1.127 +exit 1