android studio 解决 junit 错误的问题

提示错误信息如下:

Error:A problem occurred configuring project ':app'.
> Could not download junit.jar (junit:junit:4.12)
   > Could not get resource 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.jar'.
      > Could not GET 'https://jcenter.bintray.com/junit/junit/4.12/junit-4.12.jar'.
         > Connection to https://jcenter.bintray.com refused

原因是在APP 的build.gradle中的

dependencies {
    ......
    testCompile 'junit:junit:4.12'
   ......... 
}
编译测试用例时编译了'junit:junit:4.12;把该行去掉;编译出现错误如下:

D:\android_work\MyApplication\app\src\test\java\com\example\gchen\myapplication\ExampleUnitTest.java
Error:(3, 17) error: package org.junit does not exist
Error:(5, 24) error: package org.junit does not exist
Error:(11, 6) error: cannot find symbol class Test
Error:(13, 9) error: cannot find symbol method assertEquals(int,int)

原因是没有找到org.junit这个包,这个包的位置在android studio 目录下的

gradle\gradle-2.10\lib\plugins\junit-4.12.jar;把这个包复制到项目APP的libs目录下即可;

你可能感兴趣的:(android)