Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用Gradle在Eclipse中添加依赖项_Android_Eclipse_Gradle - Fatal编程技术网

Android 使用Gradle在Eclipse中添加依赖项

Android 使用Gradle在Eclipse中添加依赖项,android,eclipse,gradle,Android,Eclipse,Gradle,我正在使用Eclipse的Gradle IDE插件,并在build.Gradle文件中创建了一个自定义任务: sourceSets { unitTest { java.srcDirs = ['tests'] } } dependencies { unitTestCompile files("$project.buildDir/classes/debug") unitTestCompile 'junit:junit:4.11' unitTe

我正在使用Eclipse的Gradle IDE插件,并在build.Gradle文件中创建了一个自定义任务:

sourceSets {
    unitTest {
        java.srcDirs = ['tests']
    }
}

dependencies {
    unitTestCompile files("$project.buildDir/classes/debug")
    unitTestCompile 'junit:junit:4.11'
    unitTestCompile 'org.robolectric:robolectric:2.1.1'
    unitTestCompile 'com.google.android:android:4.0.1.2' 
}

configurations {
    unitTestCompile.extendsFrom runtime
    unitTestRuntime.extendsFrom unitTestCompile
}

task unitTest(type:Test, dependsOn: assemble) {
    description = "run unit tests"
    testClassesDir = project.sourceSets.unitTest.output.classesDir
    classpath = project.sourceSets.unitTest.runtimeClasspath
}

build.dependsOn unitTest
apply plugin: 'eclipse'
eclipse {
    classpath {    
        plusConfigurations += configurations.unitTestCompile
      }
}

问题是,我引用的依赖项没有添加到Eclipse中,我得到的错误是
import org.junit.Test
导入org.roblectric.roblectric等,无法解析。我尝试右键单击项目->渐变->刷新依赖项,但没有成功。

自己找到了解决方案。将其添加到build.gradle文件:

sourceSets {
    unitTest {
        java.srcDirs = ['tests']
    }
}

dependencies {
    unitTestCompile files("$project.buildDir/classes/debug")
    unitTestCompile 'junit:junit:4.11'
    unitTestCompile 'org.robolectric:robolectric:2.1.1'
    unitTestCompile 'com.google.android:android:4.0.1.2' 
}

configurations {
    unitTestCompile.extendsFrom runtime
    unitTestRuntime.extendsFrom unitTestCompile
}

task unitTest(type:Test, dependsOn: assemble) {
    description = "run unit tests"
    testClassesDir = project.sourceSets.unitTest.output.classesDir
    classpath = project.sourceSets.unitTest.runtimeClasspath
}

build.dependsOn unitTest
apply plugin: 'eclipse'
eclipse {
    classpath {    
        plusConfigurations += configurations.unitTestCompile
      }
}
然后右键单击project->Gradle->Refresh Dependencies