近日升级AS到3.2.1版本,新建工程时报错:
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Open File
Show Details
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Open File
Show Details
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test:runner:1.0.2.
Open File
Show Details
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.2.
Open File
Show Details
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Open File
Show Details
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Open File
Show Details
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.
Open File
Show Details
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.3.
Open File
Show Details
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve junit:junit:4.12.
Open File
Show Details
错误原因:项目默认配置了gradle 4.6版本,镜像服务器错误(mirrors.neusoft.edu.cn 没有提供下载服务)导致无法下载gradle-4.6-all.zip,无法完成编译。
解决方法1:降低gradle版本
打开 gradle/wrapper/gradle-wrapper.properties,修改gradle版本为本地已下载版本。如gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
记得同时修改build.gradle内容:3.1.0
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
解决方法2:更新到最新版本
不使用镜像地址下载gradle-4.6-all.zip,因为镜像地址连接失败,所以把它拿掉。
找到/Users/lvxiangan/.gradle文件夹,打开gradle.properties
## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Thu Dec 06 23:52:05 CST 2018
使用#号注释掉以下4行
systemProp.http.proxyHost=mirrors.neusoft.edu.cn
systemProp.http.proxyPort=80
systemProp.https.proxyHost=mirrors.neusoft.edu.cn
systemProp.https.proxyPort=80
或者删除整个文件。重启AS,可以看到正在重新下载gradle-4.6-all.zip
如果上一步下载很慢,可以通过网盘或迅雷下载到本地,从本地直接加载。
下载好复制到 /Users/lvxiangan/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg 文件夹下,然后重启AS。
注意:bcst21l2brirad8k2ben1letg 文件夹名称是由系统随机产生,请不要尝试修改它。
最后来一张成功编译图,晚安!
————————————————
版权声明:本文为CSDN博主「LVXIANGAN」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/LVXIANGAN/article/details/84860691
来源:CSDN
作者:锐湃
链接:https://blog.csdn.net/chuyouyinghe/article/details/103481584