title: Gradle build for android project RuntimeException in localTest task
body: <p>I'm trying to make an eclipse project gradle-friendly, and I'm almost there. This is my build.gradle file:</p>
  
  <pre><code>buildscript {
      repositories {
          mavenCentral()
      }
  
      dependencies {
          classpath 'com.android.tools.build:gradle:0.10.+'
      }
  }
  
  apply plugin: 'android'
  
  android {
      compileSdkVersion 19
      buildToolsVersion "19.0.3"
  
      defaultConfig {
          minSdkVersion 17
          targetSdkVersion 19
          testInstrumentationRunner "android.test.InstrumentationTestRunner"
          testPackageName "com.elegantthought.directoryandroid.test"
      }
  
      sourceSets {
          instrumentTest.setRoot('src/test')
      }
  
      lintOptions {
          abortOnError = false
      }
  }
  
  version = "0.1.0"
  
  repositories {
      def androidHome = System.getenv("ANDROID_HOME")
      mavenCentral()
      maven {
          url "$androidHome"
      }
  }
  
  sourceSets {
      testLocal {
          java.srcDir file('src/androidTest/java')
      }
  }
  
  dependencies {
      compile files(dir: 'libs', include: '*.jar')
  
      testLocalCompile 'junit:junit:4.11'
      testLocalCompile 'com.google.android:android:4.1.1.4'
      testLocalCompile 'com.google.android:android-test:4.1.1.4'
      testLocalCompile 'com.google.android:support-v4:r7'
  
      instrumentTestCompile 'junit:junit:4.11'
      instrumentTestCompile 'com.google.android:android:4.1.1.4'
      instrumentTestCompile 'com.google.android:android-test:4.1.1.4'
      instrumentTestCompile 'com.google.android:support-v4:r7'
  
      androidTestCompile('junit:junit:4.11') { exclude group: 'org.hamcrest' }
  }
  
  task localTest (type: Test, dependsOn: assemble) {
      testClassesDir = sourceSets.testLocal.output.classesDir
  
      android.sourceSets.main.java.srcDirs.each { dir -&gt;
          def buildDir = dir.getAbsolutePath().split('/')
          buildDir = (buildDir[0..(buildDir.length - 4)] + ['build', 'classes', 'debug']).join('/')
  
          sourceSets.testLocal.compileClasspath += files(buildDir)
          sourceSets.testLocal.runtimeClasspath += files(buildDir)
      }
  
      classpath = sourceSets.testLocal.runtimeClasspath
  }
  
  check.dependsOn localTest
  </code></pre>
  
  <p>Some of that stuff might not be needed, I'll trim it down when I get it working (advice there is also appreciated). My problem is that my program accesses the external storage directory. This isn't a problem when unit testing in Eclipse or running 'gradle connectedCheck', but for the localTest gradle task I get a RuntimeException on this line:</p>
  
  <pre><code>File dir = new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/download");
  </code></pre>
  
  <p>I assume this is due to the fact that there is no device from which to get the external storage directory, based on the task name and the fact that it fails in a few seconds ('gradle connectedCheck' takes about 40 seconds with the emulator already up). I've worked around aborting on lint errors (the lintOptions bit), should I do something similar here? Or, is there perhaps another dependency that I'm missing?</p>