android studio 解决 junit 错误的问题

本文介绍了当在Android Studio中配置junit单元测试框架时遇到的依赖下载失败问题及其解决方案。错误主要源于网络连接问题导致无法从jcenter.bintray.com下载junit-4.12.jar文件。文中提供了两种解决方法:一是移除build.gradle文件中对junit的依赖声明,二是手动将junit-4.12.jar文件复制到项目的libs目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

提示错误信息如下:

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目录下即可;

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值