我试图让一个日食项目符合流动,而且我几乎就在那里。这是我的build.gradle文件:
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 ->
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
可能不需要其中的一些东西,当我开始工作时我会修剪它(建议也值得赞赏)。我的问题是我的程序访问外部存储目录。在Eclipse中进行单元测试或运行“gradle connectedCheck”时,这不是问题,但对于localTest gradle任务,我在此行上获得了RuntimeException:
File dir = new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/download");
我认为这是因为没有设备可以从中获取外部存储目录,这取决于任务名称以及它在几秒钟内失败的事实(' gradle connectedCheck'仿真器已经启动需要大约40秒。我已经解决过lint错误(lintOptions位)的问题,我应该在这里做类似的事吗?或者,是否还有另一种依赖我缺席?