Use gradle to build the app instead of ant
[android/android-app-development-getting-started.git] / android-app-development-getting-started.sh
index 971aa72..123a6f2 100755 (executable)
@@ -5,26 +5,26 @@
 #
 # Similar to
 # http://vishalraj.in/blogs/hello-world-writing-my-first-android-app-on-linux
 #
 # Similar to
 # http://vishalraj.in/blogs/hello-world-writing-my-first-android-app-on-linux
-#
 
 
-# The base working dir is assumed to be $HOME/Android
-mkdir $HOME/Android
-cd $HOME/Android
+ANDROID_BASE_DIR=$HOME/Android
+
+mkdir $ANDROID_BASE_DIR
+cd $ANDROID_BASE_DIR
 
 # Download and unpack the SDK from
 # http://developer.android.com/sdk/index.html
 
 # Download and unpack the SDK from
 # http://developer.android.com/sdk/index.html
-wget http://dl.google.com/android/android-sdk_r21.1-linux.tgz
-tar xzvf android-sdk_r21.1-linux.tgz
+wget http://dl.google.com/android/android-sdk_r24.3.4-linux.tgz
+tar xzvf android-sdk_r24.3.4-linux.tgz
 
 # Add "platform-tools" and "tools" to the PATH
 
 # Add "platform-tools" and "tools" to the PATH
-export ANDROID_HOME=$HOME/Android/android-sdk-linux
+export ANDROID_HOME=$ANDROID_BASE_DIR/android-sdk-linux
 export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools
 
 # List packages
 export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools
 
 # List packages
-android list sdk --extended
+android list sdk --all --extended
 
 # Install packages. Use this same command line to update the packages
 
 # Install packages. Use this same command line to update the packages
-android update sdk --no-ui --filter platform-tools,android-17,sys-img-17,extra-android-support
+android update sdk --no-ui --all --filter tools,platform-tools,build-tools-23.0.1,android-17,sys-img-x86-android-17,extra-android-support
 
 # Check what targets are available
 android list targets
 
 # Check what targets are available
 android list targets
@@ -32,29 +32,34 @@ android list targets
 # Create an Android Virtual Device (AVD)
 android create avd --target android-17 --name android-17-x86 --abi x86
 
 # Create an Android Virtual Device (AVD)
 android create avd --target android-17 --name android-17-x86 --abi x86
 
-# Install "ant" to build packages
-sudo aptitude install ant
-
 # Create a Hello World application
 # http://developer.android.com/tools/projects/projects-cmdline.html
 # Create a Hello World application
 # http://developer.android.com/tools/projects/projects-cmdline.html
-mkdir $HOME/Android/Apps
+#
+# Info on the latest version of the Android Gradle Plugin here:
+# https://developer.android.com/tools/revisions/gradle-plugin.html
+mkdir $ANDROID_BASE_DIR/Apps
 android create project \
 android create project \
+       --gradle --gradle-version 1.3.1 \
        --target android-17 \
        --name MyFirstApp \
        --target android-17 \
        --name MyFirstApp \
-       --path $HOME/Android/Apps/MyFirstApp \
+       --path $ANDROID_BASE_DIR/Apps/MyFirstApp \
        --activity MainActivity \
        --package com.example.myfirstapp
 
        --activity MainActivity \
        --package com.example.myfirstapp
 
+# Set a gradle version compatible with the Android Gradle Plugin used above,
+# see: http://tools.android.com/tech-docs/new-build-system/version-compatibility
+sed -e '/distributionUrl/s/gradle-[^\-]*-all/gradle-2\.5-all/g' -i $ANDROID_BASE_DIR/Apps/MyFirstApp/gradle/wrapper/gradle-wrapper.properties
+sed -e 's/runProguard false/minifyEnabled false/g' -i $ANDROID_BASE_DIR/Apps/MyFirstApp/build.gradle
+
 # And maybe you want to use git for your App?
 # And maybe you want to use git for your App?
-cd $HOME/Android/Apps/MyFirstApp
-ant clean
+cd $ANDROID_BASE_DIR/Apps/MyFirstApp
+rm local.properties
 git init
 git add .
 git init
 git add .
-git rm local.properties
 git commit -m $'Initial import\n\nhttp://developer.android.com/training/basics/firstapp/creating-project.html'
 git commit -m $'Initial import\n\nhttp://developer.android.com/training/basics/firstapp/creating-project.html'
-echo "bin/" > .gitignore
-echo "gen/" > .gitignore
-echo "local.properties" > .gitignore
+echo ".gradle/" > .gitignore
+echo "build/" >> .gitignore
+echo "local.properties" >> .gitignore
 git add .gitignore
 git commit -m "Add a .gitignore file"
 
 git add .gitignore
 git commit -m "Add a .gitignore file"
 
@@ -63,8 +68,8 @@ http://developer.android.com/training/basics/firstapp/building-ui.html
 
 # Build the App
 # http://developer.android.com/tools/building/building-cmdline.html
 
 # Build the App
 # http://developer.android.com/tools/building/building-cmdline.html
-cd $HOME/Android/Apps/MyFirstApp
-ant debug
+cd $ANDROID_BASE_DIR/Apps/MyFirstApp
+./gradlew assembleDebug
 
 # Start the emulator, hardware accelerated:
 # http://developer.android.com/tools/devices/emulator.html#vm-linux
 
 # Start the emulator, hardware accelerated:
 # http://developer.android.com/tools/devices/emulator.html#vm-linux