build-scripts/androidbuild.sh
changeset 11649 fe6769530709
parent 11647 5816b27073a4
equal deleted inserted replaced
11648:ed5bc0abae1b 11649:fe6769530709
    23 
    23 
    24 if [ -z "$1" ] || [ -z "$SOURCES" ]; then
    24 if [ -z "$1" ] || [ -z "$SOURCES" ]; then
    25     echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
    25     echo "Usage: androidbuild.sh com.yourcompany.yourapp < sources.list"
    26     echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
    26     echo "Usage: androidbuild.sh com.yourcompany.yourapp source1.c source2.c ...sourceN.c"
    27     echo "To copy SDL source instead of symlinking: COPYSOURCE=1 androidbuild.sh ... "
    27     echo "To copy SDL source instead of symlinking: COPYSOURCE=1 androidbuild.sh ... "
    28     echo "You can pass additional arguments to ndk-build with the NDKARGS variable: NDKARGS=\"-s\" androidbuild.sh ..."
       
    29     exit 1
    28     exit 1
    30 fi
    29 fi
    31 
       
    32 
       
    33 
    30 
    34 SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
    31 SDLPATH="$( cd "$(dirname "$0")/.." ; pwd -P )"
    35 
    32 
    36 if [ -z "$ANDROID_HOME" ];then
    33 if [ -z "$ANDROID_HOME" ];then
    37     echo "Please set the ANDROID_HOME directory to the path of the Android SDK"
    34     echo "Please set the ANDROID_HOME directory to the path of the Android SDK"
    38     exit 1
    35     exit 1
    39 fi
    36 fi
    40 
    37 
    41 NDKBUILD=`which ndk-build`
    38 if [ ! -d "$ANDROID_HOME/ndk-bundle" -a -z "$ANDROID_NDK_HOME" ]; then
    42 if [ -z "$NDKBUILD" ];then
    39     echo "Please set the ANDROID_NDK_HOME directory to the path of the Android NDK"
    43     echo "Could not find the ndk-build utility, install Android's NDK and add it to the path"
       
    44     exit 1
    40     exit 1
    45 fi
    41 fi
    46 
       
    47 ANDROID="$ANDROID_HOME/tools/android"
       
    48 if [ ! -f "$ANDROID" ]; then
       
    49     ANDROID=`which android`
       
    50 fi
       
    51 if [ -z "$ANDROID" ];then
       
    52     echo "Could not find the android utility, install Android's SDK and add it to the path"
       
    53     exit 1
       
    54 fi
       
    55 
       
    56 NCPUS="1"
       
    57 case "$OSTYPE" in
       
    58     darwin*)
       
    59         NCPU=`sysctl -n hw.ncpu`
       
    60         ;; 
       
    61     linux*)
       
    62         if [ -n `which nproc` ]; then
       
    63             NCPUS=`nproc`
       
    64         fi  
       
    65         ;;
       
    66   *);;
       
    67 esac
       
    68 
    42 
    69 APP="$1"
    43 APP="$1"
    70 APPARR=(${APP//./ })
    44 APPARR=(${APP//./ })
    71 BUILDPATH="$SDLPATH/build/$APP"
    45 BUILDPATH="$SDLPATH/build/$APP"
    72 
    46 
   119 {
    93 {
   120 }
    94 }
   121 __EOF__
    95 __EOF__
   122 
    96 
   123 # Update project and build
    97 # Update project and build
   124 cd $BUILDPATH
    98 echo "To build and install to a device for testing, run the following:"
   125 pushd $BUILDPATH/app/jni
    99 echo "cd $BUILDPATH"
   126 $NDKBUILD -j $NCPUS $NDKARGS
   100 echo "./gradlew installDebug"
   127 popd
       
   128 
       
   129 # Start gradle build
       
   130 $BUILDPATH/gradlew build
       
   131 
       
   132 cd $CURDIR
       
   133 
       
   134 APK="$BUILDPATH/app/build/outputs/apk/app-debug.apk"
       
   135 
       
   136 if [ -f "$APK" ]; then
       
   137     echo "Your APK is ready at $APK"
       
   138     echo "To install to your device: "
       
   139     echo "$ANDROID_HOME/platform-tools/adb install -r $APK"
       
   140     exit 0
       
   141 fi
       
   142 
       
   143 echo "There was an error building the APK"
       
   144 exit 1