在下载好各种依赖及启动虚拟机后,运行android app, 在build过程中会报错 connect fail,log中会有错误信息例如:
“Could not resolve all files for configuration ':app:_internal_aapt2_binary'.”
“Connect to 127.0.0.1:7890 [/127.0.0.1] failed: Connection refused (Connection refused)”
查了一些文章,做了三处修改,不确定是哪个生效了,大家可以挨个试一下。
1. 修改build.gradle中的配置

初次创建工程时,build.gradle中默认为:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
参考网上大家分享的修改,把jcenter()注释掉后增加了一些maven地址,如下
buildscript {
repositories {
google()
//jcenter()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'https://maven.aliyun.com/repository/public/' }
maven { url 'https://maven.aliyun.com/repository/google/' }
maven { url 'https://maven.aliyun.com/repository/jcenter/' }
maven { url 'https://maven.aliyun.com/repository/central/' }
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
//jcenter()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
}
}
根据as的弹窗提示选择“sync now”,会重新下载很多包。
2. 关掉proxy setting
做完第一步之后build还是会报错,彻底关掉as之后,重新打开,在HTTP Proxy设置中将“Auto-dectect proxy settings" 切换为 “No proxy".
3. 注释掉自动生成的proxyhost和proxyport配置
第三步做完就,BUILD SUCCESSFUL啦!
版权声明:本文为BuXuTou原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。