社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
as版本:3.5.2
学习Android开发,创建第一个项目的时候报错:
ERROR: Unable to resolve dependency for ‘:app@debugAndroidTest/compileClasspath’: Could not download junit.jar (junit:junit:4.12)
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ‘:app@debugUnitTest/compileClasspath’: Could not download junit.jar (junit:junit:4.12)
Show Details
Affected Modules: app
解决方式如下:
1 把项目的build.gradle文件更改如下:
buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
// jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
// 添加阿里云 maven 地址
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
// jcenter()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2 在File-Settings中修改代理
3
4 点击sync
5 如果出现证书错误,可以参考这篇文章下载阿里云证书
https://blog.csdn.net/weixin_45607439/article/details/100672602
之后项目不再报错。
参考文章:https://blog.csdn.net/jiangbw415/article/details/81675346?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
https://blog.csdn.net/weixin_40849588/article/details/86559842?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
https://blog.csdn.net/u013806583/article/details/92846180
直接注释掉build.gradle中的junit依赖,也可以不报错,但是不推荐
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!