【Android TimeCat】 解决Gradle :Resolve dependencies :classpath的办法

背景

想学习一下别人的成型项目FastHub,结果build失败,gradle信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Executing tasks: [assemble]

Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'FastHub'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:3.2.0-alpha04.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:3.2.0-alpha04.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.0-alpha04/gradle-3.2.0-alpha04.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.0-alpha04/gradle-3.2.0-alpha04.pom'.
> Connect to dl.google.com:443 [dl.google.com/2404:6800:4008:c01:0:0:0:88] failed: Connection timed out: connect
> Could not resolve com.android.tools.build:gradle:3.2.0-alpha04.
Required by:
project : > com.apollographql.apollo:gradle-plugin:0.4.1
> Could not resolve com.android.tools.build:gradle:3.2.0-alpha04.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.0-alpha04/gradle-3.2.0-alpha04.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.0-alpha04/gradle-3.2.0-alpha04.pom'.
> Connect to dl.google.com:443 [dl.google.com/2404:6800:4008:c01:0:0:0:88] failed: Connection timed out: connect

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3m 18s

首先在设置>proxy里使用系统默认代理,check connection 使用'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.0-alpha04/gradle-3.2.0-alpha04.pom'完美通过,心想应该不是proxy的问题。可就是build失败,提示要么Connection timed out,要么unknown host: dl.google.com,简直逼疯。最后参考了一下,死马当活马医,在参考的文章里找到了解决方案。(我参考的不只下面的3个参考页面,开了一大堆csdn、StackOverflow、github issue的相关网页,都没解决,这3个是我解决时的参考,所以放这里了)

解决

在项目目录下新建文件gradle.properties:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
## Project-wide Gradle settings.
#
# 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
#Fri Mar 09 22:26:51 CST 2018
systemProp.https.proxyPort=1080
systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080

内容意思是使用本地127.0.0.1:8000端口进行代理。

注意:

  • gradle.propertiesapp文件夹同级,而不是在app文件夹内。
  • 记得把shadowsocks挂到1080端口,之前的check connection没卵用。

参考

当前网速较慢或者你使用的浏览器不支持博客特定功能,请尝试刷新或换用Chrome、Firefox等现代浏览器