Revert "Update Android Apps to use gradle"

This reverts commit 425535f1626932e4e22f61a2571f9c3c2b1c5977.

NOTRY=true
NOTREECHECKS=true
TBR=djsollen@google.com
BUG=skia:
DOCS_PREVIEW= https://skia.org/?cl=1250233002

Review URL: https://codereview.chromium.org/1250233002
diff --git a/.gitignore b/.gitignore
index 7ea8256..44d423f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,9 @@
 *.pyc
 *.swp
-*.iml
 .DS_Store
 .android_config
 .gclient*
 .gm-actuals
-.gradle
-.idea
 .cproject
 .project
 .settings/
@@ -15,10 +12,6 @@
 common
 gyp/build
 out
-platform_tools/android/apps/build
-platform_tools/android/apps/*.properties
-platform_tools/android/apps/*/build
-platform_tools/android/apps/*/src/main/libs
 platform_tools/chromeos/third_party/externals
 platform_tools/chromeos/toolchain
 skps
diff --git a/platform_tools/android/apps/sample_app/src/main/AndroidManifest.xml b/platform_tools/android/app/AndroidManifest.xml
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/AndroidManifest.xml
rename to platform_tools/android/app/AndroidManifest.xml
diff --git a/platform_tools/android/app/build.xml b/platform_tools/android/app/build.xml
new file mode 100644
index 0000000..fbba716
--- /dev/null
+++ b/platform_tools/android/app/build.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="SkiaAndroid" default="help">
+
+    <!-- The local.properties file is created and updated by the 'android' tool.
+         It contains the path to the SDK. It should *NOT* be checked into
+         Version Control Systems. -->
+    <property file="local.properties" />
+
+    <!-- The project.properties file is created and updated by the 'android'
+         tool, as well as ADT.
+
+         This contains project specific properties such as project target, and library
+         dependencies. Lower level build properties are stored in ant.properties
+         (or in .classpath for Eclipse projects).
+
+         This file is an integral part of the build system for your
+         application and should be checked into Version Control Systems. -->
+    <loadproperties srcFile="project.properties" />
+
+    <!-- quick check on sdk.dir -->
+    <fail
+            message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
+            unless="sdk.dir"
+    />
+
+    <!--
+        Import per project custom build rules if present at the root of the project.
+        This is the place to put custom intermediary targets such as:
+            -pre-build
+            -pre-compile
+            -post-compile (This is typically used for code obfuscation.
+                           Compiled code location: ${out.classes.absolute.dir}
+                           If this is not done in place, override ${out.dex.input.absolute.dir})
+            -post-package
+            -post-build
+            -pre-clean
+    -->
+    <import file="custom_rules.xml" optional="true" />
+
+    <!-- Import the actual build file.
+
+         To customize existing targets, there are two options:
+         - Customize only one target:
+             - copy/paste the target into this file, *before* the
+               <import> task.
+             - customize it to your needs.
+         - Customize the whole content of build.xml
+             - copy/paste the content of the rules files (minus the top node)
+               into this file, replacing the <import> task.
+             - customize to your needs.
+
+         ***********************
+         ****** IMPORTANT ******
+         ***********************
+         In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
+         in order to avoid having your file be overridden by tools such as "android update project"
+    -->
+    <!-- version-tag: 1 -->
+    <import file="${sdk.dir}/tools/ant/build.xml" />
+
+</project>
diff --git a/platform_tools/android/apps/sample_app/src/main/jni/AndroidKeyToSkKey.h b/platform_tools/android/app/jni/AndroidKeyToSkKey.h
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/jni/AndroidKeyToSkKey.h
rename to platform_tools/android/app/jni/AndroidKeyToSkKey.h
diff --git a/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp b/platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.cpp
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp
rename to platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.cpp
diff --git a/platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.h b/platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.h
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.h
rename to platform_tools/android/app/jni/com_skia_SkiaSampleRenderer.h
diff --git a/platform_tools/android/app/project.properties b/platform_tools/android/app/project.properties
new file mode 100644
index 0000000..4ab1256
--- /dev/null
+++ b/platform_tools/android/app/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
diff --git a/platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_next.png b/platform_tools/android/app/res/drawable-hdpi/ic_btn_find_next.png
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_next.png
rename to platform_tools/android/app/res/drawable-hdpi/ic_btn_find_next.png
Binary files differ
diff --git a/platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_prev.png b/platform_tools/android/app/res/drawable-hdpi/ic_btn_find_prev.png
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/res/drawable-hdpi/ic_btn_find_prev.png
rename to platform_tools/android/app/res/drawable-hdpi/ic_btn_find_prev.png
Binary files differ
diff --git a/platform_tools/android/apps/sample_app/src/main/res/layout/layout.xml b/platform_tools/android/app/res/layout/layout.xml
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/res/layout/layout.xml
rename to platform_tools/android/app/res/layout/layout.xml
diff --git a/platform_tools/android/apps/sample_app/src/main/res/menu/action_bar.xml b/platform_tools/android/app/res/menu/action_bar.xml
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/res/menu/action_bar.xml
rename to platform_tools/android/app/res/menu/action_bar.xml
diff --git a/platform_tools/android/apps/sample_app/src/main/res/values/strings.xml b/platform_tools/android/app/res/values/strings.xml
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/res/values/strings.xml
rename to platform_tools/android/app/res/values/strings.xml
diff --git a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java b/platform_tools/android/app/src/com/skia/SkiaSampleActivity.java
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java
rename to platform_tools/android/app/src/com/skia/SkiaSampleActivity.java
diff --git a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleRenderer.java b/platform_tools/android/app/src/com/skia/SkiaSampleRenderer.java
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleRenderer.java
rename to platform_tools/android/app/src/com/skia/SkiaSampleRenderer.java
diff --git a/platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java b/platform_tools/android/app/src/com/skia/SkiaSampleView.java
similarity index 100%
rename from platform_tools/android/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java
rename to platform_tools/android/app/src/com/skia/SkiaSampleView.java
diff --git a/platform_tools/android/apps/build.gradle b/platform_tools/android/apps/build.gradle
deleted file mode 100644
index b20334b..0000000
--- a/platform_tools/android/apps/build.gradle
+++ /dev/null
@@ -1,86 +0,0 @@
-// Top-level build file where you can add configuration options common to all sub-projects/modules.
-
-buildscript {
-    repositories {
-        jcenter()
-    }
-    dependencies {
-        classpath 'com.android.tools.build:gradle:1.2.3'
-
-        // NOTE: Do not place your application dependencies here; they belong
-        // in the individual module build.gradle files
-    }
-}
-
-allprojects {
-    repositories {
-        jcenter()
-    }
-}
-
-def getLocalProperties() {
-    Properties properties = new Properties()
-    File propFile = project.rootProject.file('local.properties')
-    if (propFile.canRead()) {
-        properties.load(propFile.newDataInputStream())
-    }
-    propFile = project.rootProject.file('gradle.properties')
-    if (propFile.canRead()) {
-        properties.load(propFile.newDataInputStream())
-    }
-    return properties
-}
-
-def getSDKPath() {
-    String path = System.getenv("ANDROID_SDK_ROOT")
-    if (path == null) {
-        path = getLocalProperties().getProperty('sdk.dir', null)
-    }
-
-    if (path == null) {
-        throw new GradleScriptException("Android SDK not found! Please set ANDROID_SDK_ROOT to" +
-                                        " your path or define sdk.dir in gradle.properties")
-    }
-    return path
-}
-
-def getPathWithDepotTools() {
-    System.getenv("PATH") + ":" + getLocalProperties().getProperty('depot_tools.dir', null)
-    String path = System.getenv("PATH")
-    if (!path.contains("depot_tools")) {
-        path += ":" + getLocalProperties().getProperty('depot_tools.dir', null)
-    }
-
-    if (!path.contains("depot_tools")) {
-        throw GradleScriptException("Depot Tools not found! Please update your path to include" +
-                                    " depot_tools or define depot_tools.dir in gradle.properties")
-    }
-    return path
-}
-
-def constructBuildCommand(variant, buildTarget) {
-    String cmdLine = "./platform_tools/android/bin/android_ninja $buildTarget"
-    String deviceType = null
-    if (variant.name.startsWith("arm64")) {
-        deviceType = "arm64"
-    } else if (variant.name.startsWith("arm")) {
-        deviceType = "arm_v7_neon"
-    } else if (variant.name.startsWith("x86_64")) {
-        deviceType = "x86_64"
-    } else if (variant.name.startsWith("x86")) {
-        deviceType = "x86"
-    } else if (variant.name.startsWith("mips")) {
-        deviceType = "mips"
-    } else if (variant.name.startsWith("mips64")) {
-        deviceType = "mips64"
-    }
-
-    if (deviceType != null) {
-        cmdLine += " -d " + deviceType
-    }
-
-    if (variant.name.endsWith("Release")) {
-        cmdLine += " --release"
-    }
-    return cmdLine
-}
\ No newline at end of file
diff --git a/platform_tools/android/apps/sample_app/build.gradle b/platform_tools/android/apps/sample_app/build.gradle
deleted file mode 100644
index e27a77a..0000000
--- a/platform_tools/android/apps/sample_app/build.gradle
+++ /dev/null
@@ -1,46 +0,0 @@
-apply plugin: 'com.android.application'
-
-android {
-    compileSdkVersion 19
-    buildToolsVersion "22.0.1"
-
-    defaultConfig {
-        applicationId "com.skia.sample_app"
-        minSdkVersion 9
-        targetSdkVersion 19
-        versionCode 1
-        versionName "1.0"
-    }
-
-    sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call
-    sourceSets.main.jniLibs.srcDir "src/main/libs"
-
-    productFlavors {
-        arm {}
-        arm64 {}
-        x86 {}
-        x86_64 {}
-        mips {}
-        mips64 {}
-    }
-
-    // make sure that app is built and shared libraries are copied to correct directories
-    applicationVariants.all{ variant ->
-
-        def buildNativeLib = task("${variant.name}_NativeLib", type:Exec) {
-            workingDir '../../../..' // top-level skia directory
-            commandLine constructBuildCommand(variant, "CopySampleAppDeps").split()
-            environment PATH: getPathWithDepotTools()
-            environment ANDROID_SDK_ROOT: getSDKPath()
-        }
-
-        if (!hasProperty("suppressNativeBuild")) {
-            TaskCollection<Task> assembleTask
-            assembleTask = project.tasks.matching {
-                it.name.contains("assemble") &&
-                        it.name.toLowerCase().endsWith(variant.name.toLowerCase())
-            }
-            assembleTask.getAt(0).dependsOn buildNativeLib
-        }
-    }
-}
\ No newline at end of file
diff --git a/platform_tools/android/apps/settings.gradle b/platform_tools/android/apps/settings.gradle
deleted file mode 100644
index 89cc954..0000000
--- a/platform_tools/android/apps/settings.gradle
+++ /dev/null
@@ -1,2 +0,0 @@
-include ':sample_app'
-include ':visualbench'
diff --git a/platform_tools/android/apps/visualbench/build.gradle b/platform_tools/android/apps/visualbench/build.gradle
deleted file mode 100644
index 81322b0..0000000
--- a/platform_tools/android/apps/visualbench/build.gradle
+++ /dev/null
@@ -1,46 +0,0 @@
-apply plugin: 'com.android.application'
-
-android {
-    compileSdkVersion 19
-    buildToolsVersion "22.0.1"
-
-    defaultConfig {
-        applicationId "com.skia.visualbench"
-        minSdkVersion 9
-        targetSdkVersion 19
-        versionCode 1
-        versionName "1.0"
-    }
-
-    sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call
-    sourceSets.main.jniLibs.srcDir "src/main/libs"
-
-    productFlavors {
-        arm {}
-        arm64 {}
-        x86 {}
-        x86_64 {}
-        mips {}
-        mips64 {}
-    }
-
-    // make sure that app is built and shared libraries are copied to correct directories
-    applicationVariants.all{ variant ->
-
-        def buildNativeLib = task("${variant.name}_NativeLib", type:Exec) {
-            workingDir '../../../..' // top-level skia directory
-            commandLine constructBuildCommand(variant, "CopyVisualBenchDeps").split()
-            environment PATH: getPathWithDepotTools()
-            environment ANDROID_SDK_ROOT: getSDKPath()
-        }
-
-        if (!hasProperty("suppressNativeBuild")) {
-            TaskCollection<Task> assembleTask
-            assembleTask = project.tasks.matching {
-                it.name.contains("assemble") &&
-                        it.name.toLowerCase().endsWith(variant.name.toLowerCase())
-            }
-            assembleTask.getAt(0).dependsOn buildNativeLib
-        }
-    }
-}
\ No newline at end of file
diff --git a/platform_tools/android/bin/android_install_app b/platform_tools/android/bin/android_install_app
index ed5ed61..a8c1a12 100755
--- a/platform_tools/android/bin/android_install_app
+++ b/platform_tools/android/bin/android_install_app
@@ -9,7 +9,7 @@
   echo "                  -h  Prints this help message"
   echo "            --release Install the release build of Skia"
   echo "      -s [device_s/n] Serial number of the device to be used"
-  echo "              AppName Can be either sample_app or VisualBench"
+  echo "              AppName Can be either SampleApp or VisualBench"
 }
 
 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@@ -18,6 +18,8 @@
 source $SCRIPT_DIR/utils/setup_adb.sh
 
 forceRemoval="false"
+installLauncher="false"
+installOptions="-r"
 app=""
 
 for arg in ${APP_ARGS[@]}; do
@@ -43,8 +45,8 @@
 done
 
 if [[ ${app} == "" ]]; then
-  echo "defaulting to installing sample_app."
-  app="sample_app"
+  echo "defaulting to installing SampleApp."
+  app="SampleApp"
 fi
 
 
@@ -54,8 +56,6 @@
     $ADB ${DEVICE_SERIAL} uninstall com.skia > /dev/null
 fi
 
-BUILD_TYPE_LC=$(echo $BUILDTYPE | tr "[:upper:]" "[:lower:]")
-
-echo "Installing ${app} from ${app}/build/outputs/apk/${app}-${ANDROID_ARCH}-${BUILD_TYPE_LC}.apk"
-$ADB ${DEVICE_SERIAL} install -r ${SCRIPT_DIR}/../apps/${app}/build/outputs/apk/${app}-${ANDROID_ARCH}-${BUILD_TYPE_LC}.apk
+echo "Installing ${app} from ${SKIA_OUT}/${BUILDTYPE}"
+$ADB ${DEVICE_SERIAL} install ${installOptions} ${SKIA_OUT}/${BUILDTYPE}/android/${app}/bin/${app}.apk
 
diff --git a/platform_tools/android/bin/android_setup.sh b/platform_tools/android/bin/android_setup.sh
index 5396294..94ae87f 100755
--- a/platform_tools/android/bin/android_setup.sh
+++ b/platform_tools/android/bin/android_setup.sh
@@ -70,11 +70,6 @@
   fi
 fi
 
-if [ -z "$ANDROID_HOME" ]; then
-  echo "ANDROID_HOME not set so we are setting it to a default value of ANDROID_SDK_ROOT"
-  exportVar ANDROID_HOME $ANDROID_SDK_ROOT
-fi
-
 # check to see that gclient sync ran successfully
 THIRD_PARTY_EXTERNAL_DIR=${SCRIPT_DIR}/../third_party/externals
 if [ ! -d "$THIRD_PARTY_EXTERNAL_DIR" ]; then
diff --git a/platform_tools/android/gyp/dependencies.gypi b/platform_tools/android/gyp/dependencies.gypi
index 036abf2..8be6836 100644
--- a/platform_tools/android/gyp/dependencies.gypi
+++ b/platform_tools/android/gyp/dependencies.gypi
@@ -287,7 +287,7 @@
           }],
         ],
         'sources': [
-          '../apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp',
+          '../app/jni/com_skia_SkiaSampleRenderer.cpp',
         ],
       },
     },
@@ -320,8 +320,8 @@
           '../../../tools/VisualBench/',
         ],
         'sources': [
-          '../apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp',
-          '../apps/visualbench/src/main/jni/main.cpp',
+          '../visualbench/jni/SkOSWindow_AndroidNative.cpp',
+          '../visualbench/jni/main.cpp',
         ],
       },
     },
diff --git a/platform_tools/android/gyp/skia_android.gypi b/platform_tools/android/gyp/skia_android.gypi
index 6ffb49c..e8bf1c3 100644
--- a/platform_tools/android/gyp/skia_android.gypi
+++ b/platform_tools/android/gyp/skia_android.gypi
@@ -12,31 +12,24 @@
     'conditions': [
       [ 'skia_arch_type == "arm" and arm_version != 7', {
         'android_arch%': "armeabi",
-        'android_variant%': "arm",
       }],
       [ 'skia_arch_type == "arm" and arm_version == 7', {
         'android_arch%': "armeabi-v7a",
-        'android_variant%': "arm",
       }],
       [ 'skia_arch_type == "arm64"', {
         'android_arch%': "arm64-v8a",
-        'android_variant%': "arm64",
       }],
       [ 'skia_arch_type == "x86"', {
         'android_arch%': "x86",
-        'android_variant%': "x86",
       }],
       [ 'skia_arch_type == "x86_64"', {
         'android_arch%': "x86_64",
-        'android_variant%': "x86_64",
       }],
       [ 'skia_arch_type == "mips" and skia_arch_width == 32', {
         'android_arch%': "mips",
-        'android_variant%': "mips",
       }],
       [ 'skia_arch_type == "mips" and skia_arch_width == 64', {
         'android_arch%': "mips64",
-        'android_variant%': "mips64",
       }],
     ],
   },
@@ -55,7 +48,7 @@
         # libraries to copy, this will cause an error in Make, but the app will
         # still build.
         {
-          'destination': '<(android_base)/apps/sample_app/src/main/libs/<(android_arch)',
+          'destination': '<(PRODUCT_DIR)/android/SampleApp/libs/<(android_arch)',
           'conditions': [
             [ 'skia_shared_lib', {
               'files': [
@@ -76,25 +69,40 @@
       'dependencies': [
         'CopySampleAppDeps',
       ],
+      'variables': {
+         'ANDROID_SDK_ROOT': '<!(echo $ANDROID_SDK_ROOT)',
+         # the ninja generator treats PRODUCT_DIR as a relative path to the
+         # gyp directory but android ant build wants a path relative to the
+         # build.xml file so we do that adjustment here.
+         'ANDROID_OUT': '../../<(PRODUCT_DIR)/android/SampleApp'
+       },
       'actions': [
         {
           'action_name': 'SampleApp_apk',
           'inputs': [
-            '<(android_base)/apps/sample_app/src/main/AndroidManifest.xml',
-            '<(android_base)/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.h',
-            '<(android_base)/apps/sample_app/src/main/jni/com_skia_SkiaSampleRenderer.cpp',
-            '<(android_base)/apps/sample_app/src/main/java/com/skia/SkiaSampleActivity.java',
-            '<(android_base)/apps/sample_app/src/main/java/com/skia/SkiaSampleRenderer.java',
-            '<(android_base)/apps/sample_app/src/main/java/com/skia/SkiaSampleView.java',
+            '<(android_base)/app/AndroidManifest.xml',
+            '<(android_base)/app/build.xml',
+            '<(android_base)/app/project.properties',
+            '<(android_base)/app/jni/com_skia_SkiaSampleRenderer.h',
+            '<(android_base)/app/jni/com_skia_SkiaSampleRenderer.cpp',
+            '<(android_base)/app/src/com/skia/SkiaSampleActivity.java',
+            '<(android_base)/app/src/com/skia/SkiaSampleRenderer.java',
+            '<(android_base)/app/src/com/skia/SkiaSampleView.java',
           ],
           'outputs': [
-            '<(android_base)/apps/sample_app/build',
+            '<(PRODUCT_DIR)/../android/SampleApp/bin/SampleApp.apk',
           ],
           'action': [
-            '<(android_base)/apps/gradlew',
-            ':sample_app:assemble<(android_variant)Debug',
-            '-p<(android_base)/apps/sample_app',
-            '-PsuppressNativeBuild',
+            'ant',
+            '-quiet',
+            '-f',
+            '<(android_base)/app/build.xml',
+            '-Dout.dir=<(ANDROID_OUT)/bin',
+            '-Dgen.absolute.dir=<(ANDROID_OUT)/gen',
+            '-Dnative.libs.absolute.dir=<(ANDROID_OUT)/libs',
+            '-Dout.final.file=<(ANDROID_OUT)/bin/SampleApp.apk',
+            '-Dsdk.dir=<(ANDROID_SDK_ROOT)',
+            'debug',
           ],
         },
       ],
@@ -114,7 +122,7 @@
         # libraries to copy, this will cause an error in Make, but the app will
         # still build.
         {
-          'destination': '<(android_base)/apps/visualbench/src/main/libs/<(android_arch)',
+          'destination': '<(PRODUCT_DIR)/android/VisualBench/libs/<(android_arch)',
           'conditions': [
             [ 'skia_shared_lib', {
               'files': [
@@ -135,21 +143,36 @@
       'dependencies': [
         'CopyVisualBenchDeps',
       ],
+      'variables': {
+         'ANDROID_SDK_ROOT': '<!(echo $ANDROID_SDK_ROOT)',
+         # the ninja generator treats PRODUCT_DIR as a relative path to the
+         # gyp directory but android ant build wants a path relative to the
+         # build.xml file so we do that adjustment here.
+         'ANDROID_OUT': '../../<(PRODUCT_DIR)/android/VisualBench/'
+       },
       'actions': [
         {
           'action_name': 'SkiaVisualBench_apk',
           'inputs': [
-            '<(android_base)/apps/visualbench/src/main/AndroidManifest.xml',
-            '<(android_base)/apps/visualbench/src/main/java/com/skia/VisualBenchActivity.java',
+            '<(android_base)/visualbench/AndroidManifest.xml',
+            '<(android_base)/visualbench/build.xml',
+            '<(android_base)/visualbench/project.properties',
+            '<(android_base)/visualbench/src/com/skia/VisualBenchActivity.java',
           ],
           'outputs': [
-            '<(android_base)/apps/visualbench/build',
+            '<(PRODUCT_DIR)/../android/VisualBench/bin/VisualBench.apk',
           ],
           'action': [
-            '<(android_base)/apps/gradlew',
-            ':visualbench:assemble<(android_variant)Debug',
-            '-p<(android_base)/apps/visualbench',
-            '-PsuppressNativeBuild',
+            'ant',
+            '-quiet',
+            '-f',
+            '<(android_base)/visualbench/build.xml',
+            '-Dout.dir=<(ANDROID_OUT)/bin',
+            '-Dgen.absolute.dir=<(ANDROID_OUT)/gen',
+            '-Dnative.libs.absolute.dir=<(ANDROID_OUT)/libs',
+            '-Dout.final.file=<(ANDROID_OUT)/bin/VisualBench.apk',
+            '-Dsdk.dir=<(ANDROID_SDK_ROOT)',
+            'debug',
           ],
         },
       ],
diff --git a/platform_tools/android/apps/visualbench/src/main/AndroidManifest.xml b/platform_tools/android/visualbench/AndroidManifest.xml
similarity index 100%
rename from platform_tools/android/apps/visualbench/src/main/AndroidManifest.xml
rename to platform_tools/android/visualbench/AndroidManifest.xml
diff --git a/platform_tools/android/visualbench/build.xml b/platform_tools/android/visualbench/build.xml
new file mode 100644
index 0000000..61df264
--- /dev/null
+++ b/platform_tools/android/visualbench/build.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="VisualBench" default="help">
+
+    <!-- The local.properties file is created and updated by the 'android' tool.
+         It contains the path to the SDK. It should *NOT* be checked into
+         Version Control Systems. -->
+    <property file="local.properties" />
+
+    <!-- The project.properties file is created and updated by the 'android'
+         tool, as well as ADT.
+
+         This contains project specific properties such as project target, and library
+         dependencies. Lower level build properties are stored in ant.properties
+         (or in .classpath for Eclipse projects).
+
+         This file is an integral part of the build system for your
+         application and should be checked into Version Control Systems. -->
+    <loadproperties srcFile="project.properties" />
+
+    <!-- quick check on sdk.dir -->
+    <fail
+            message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
+            unless="sdk.dir"
+    />
+
+    <!--
+        Import per project custom build rules if present at the root of the project.
+        This is the place to put custom intermediary targets such as:
+            -pre-build
+            -pre-compile
+            -post-compile (This is typically used for code obfuscation.
+                           Compiled code location: ${out.classes.absolute.dir}
+                           If this is not done in place, override ${out.dex.input.absolute.dir})
+            -post-package
+            -post-build
+            -pre-clean
+    -->
+    <import file="custom_rules.xml" optional="true" />
+
+    <!-- Import the actual build file.
+
+         To customize existing targets, there are two options:
+         - Customize only one target:
+             - copy/paste the target into this file, *before* the
+               <import> task.
+             - customize it to your needs.
+         - Customize the whole content of build.xml
+             - copy/paste the content of the rules files (minus the top node)
+               into this file, replacing the <import> task.
+             - customize to your needs.
+
+         ***********************
+         ****** IMPORTANT ******
+         ***********************
+         In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
+         in order to avoid having your file be overridden by tools such as "android update project"
+    -->
+    <!-- version-tag: 1 -->
+    <import file="${sdk.dir}/tools/ant/build.xml" />
+
+</project>
diff --git a/platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp b/platform_tools/android/visualbench/jni/SkOSWindow_AndroidNative.cpp
similarity index 100%
rename from platform_tools/android/apps/visualbench/src/main/jni/SkOSWindow_AndroidNative.cpp
rename to platform_tools/android/visualbench/jni/SkOSWindow_AndroidNative.cpp
diff --git a/platform_tools/android/apps/visualbench/src/main/jni/main.cpp b/platform_tools/android/visualbench/jni/main.cpp
similarity index 100%
rename from platform_tools/android/apps/visualbench/src/main/jni/main.cpp
rename to platform_tools/android/visualbench/jni/main.cpp
diff --git a/platform_tools/android/visualbench/project.properties b/platform_tools/android/visualbench/project.properties
new file mode 100644
index 0000000..4ab1256
--- /dev/null
+++ b/platform_tools/android/visualbench/project.properties
@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-19
diff --git a/platform_tools/android/apps/visualbench/src/main/java/com/skia/VisualBenchActivity.java b/platform_tools/android/visualbench/src/com/skia/VisualBenchActivity.java
similarity index 100%
rename from platform_tools/android/apps/visualbench/src/main/java/com/skia/VisualBenchActivity.java
rename to platform_tools/android/visualbench/src/com/skia/VisualBenchActivity.java
diff --git a/site/user/quick/android.md b/site/user/quick/android.md
index 57d45d5..44e3161 100644
--- a/site/user/quick/android.md
+++ b/site/user/quick/android.md
@@ -10,12 +10,20 @@
 
 The following libraries/utilities are required in addition to those needed for a standard skia checkout:
 
+  * Apache Ant
   * The Android SDK: http://developer.android.com/sdk/
 
+~~~~
+$ sudo apt-get install ant git
+~~~~
+
 Check out the source code
 -------------------------
 
-Follow the instructions [here](../download) for downloading the Skia source. 
+Follow the instructions [here](../download) for downloading the Skia source. Modify .gclient to add the following line to
+the bottom, and then run gclient sync again:
+
+    target_os = ["android"]
 
 Inside your Skia checkout, `platform_tools/android` contains the Android setup
 scripts, Android specific dependencies, and the Android Sample App.
@@ -55,7 +63,6 @@
 ninja (see descriptions of some of the other flags here).
 
     export ANDROID_SDK_ROOT=/path/to/android/sdk
-    export ANDROID_HOME=/path/to/android/sdk
     export PATH=$PATH:/path/to/depot_tools
 
     cd skia
@@ -128,7 +135,7 @@
 
 The SampleApp on Android provides a simple UI for viewing sample slides and gm images.
 
-    BUILDTYPE=Debug ./platform_tools/android/bin/android_ninja -d $TARGET_DEVICE SampleApp_APK
+    BUILDTYPE=Debug ./platform_tools/android/bin/android_ninja -d $TARGET_DEVICE
 
 Then, install the app onto the device:
 
@@ -148,28 +155,6 @@
     --resourcePath /data/local/tmp/skia_resoures 
     --pictureDir /data/local/tmp/skia_skp
 
-
-Android Studio Support
------------------------
-
-You can also build and run SampleApp (and some other experimental apps) using Android
-Studio.  To create the project either select "import project" from the quickstart
-screen or use File -> Open.  In both cases you'll need to select ./platform_tools/android/apps
-as the root directory of your project.
-
-Finally to be able to build within Android studio it needs to know the path to 
-ninja so you will need to add a properties file and populate it with the path
-to depot_tools.  The syntax and location of that file is...
- 
-    # 
-    # file location: ./platform_tools/android/apps/gradle.properties
-    #
-    depot_tools.dir=<path_to_depot_tools>
-    
-That should be all the setup you need.  You should now be able to build and deploy
-SampleApp on ARM, Intel, and MIPS devices.
-
-
 Build tools
 -----------