Android studio 错误:包org.hamcrest不存在Android Studio 1.5.1

Android studio 错误:包org.hamcrest不存在Android Studio 1.5.1,android-studio,junit,hamcrest,Android Studio,Junit,Hamcrest,我正在使用Android studio 1.5.1。 我的身材.gradle如下所示 allprojects { repositories { maven { url 'http://repo1.maven.org/maven2' } } } buildscript { repositories { jcenter() } dependencies {

我正在使用Android studio 1.5.1。 我的身材.gradle如下所示

allprojects {
        repositories {
            maven { url 'http://repo1.maven.org/maven2' }
        }
    }

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.5.0'
        }
    }
    apply plugin: 'com.android.application'

    dependencies {
        // Unit testing dependencies
        testCompile 'org.hamcrest:hamcrest-library:1.3'
        testCompile 'junit:junit:4.12'
    }
我正在为我的应用程序编写一些JUNIT测试用例,如下所示

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

public void testSomething throws Exception {
        ...
        assertThat(result, is(true));
}
但当我运行测试时,它显示

错误:包org.hamcrest不存在

错误:找不到符号assertThat(结果为(true))

但是我可以从studio转到assertThat、org.hamcrest等的定义,通过转到studio反编译JAR的定义。 我还可以在.gradle/caches中看到下载的包

有人能告诉我我做错了什么吗?
通常使用assertFalse、assertTrue等的Junit测试用例正在工作,只有hamcrest匹配给出错误。

将其添加到您的libs文件夹

右键单击jar,然后单击addaslibrary

我也有同样的问题让它找到junit。看起来Gradle没有做好自己的工作

我已提交错误报告,请注明:

从手动添加jar

将其添加到您的libs文件夹

右键单击jar,然后单击addaslibrary

我也有同样的问题让它找到junit。看起来Gradle没有做好自己的工作

我已提交错误报告,请注明:

谢谢,只有这个解决方案有效。只需要添加依赖项{compilefiles('libs/hamcrest-all-1.3.jar')testCompile'junit:junit:4.12'}是的。我怀疑您在gradle文件中修改了sourceSet是吗?是!这有什么关系?我想这是格雷德尔的一个错误。如果您修改了源代码集,
androidTestCompile
不起作用谢谢,只有这个解决方案起作用。只需要添加依赖项{compilefiles('libs/hamcrest-all-1.3.jar')testCompile'junit:junit:4.12'}是的。我怀疑您在gradle文件中修改了sourceSet是吗?是!这有什么关系?我想这是格雷德尔的一个错误。如果您修改了源代码集,
androidTestCompile
不起作用