Android Studio安装完成,新创建工程提示以下信息:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'MyApplication'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:xxx.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:xxx.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/xxx/gradle-xxx.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/xxx/gradle-xxx.pom'.
> Connect to dl.google.com:443 [dl.google.com/172.217.26.14, dl.google.com/2404:6800:4004:809:0:0:0:200e] failed: No route to host (connect failed)
意思是无法访问dl.google.com这个域名,用命令ping这个域名的确是无法访问,Android 工程的构建过程很多步骤需要访问这个域名
解决方法:
1.修改项目根目录下的build.gradle文件,使用国内地址构建,如下:
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
}
}
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
}
}
问题是解决了,但是麻烦也不利于代码同步
2.查询dl.google.com在国内的可用IP
image.png
修改电脑hosts文件,镜像国内域名访问,配置如下:
Mac下:Finder->前往->前往文件夹(输入etc/hosts):文件拷贝出来,打开后末尾添加:
203.208.43.71 dl.google.com修改完成后替换hosts文件即可。
Windows访问系统hosts文件,修改方式相同。
网友评论