操作系统是 Linux
android studio 从空模板创建工程后, 均无法编译
显示 Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly
搜索过很多帖子, 装过 Android Studio Flamingo 和电摇, 清过 cache, 重新试过多个版本的 gradle , 还是一样。
还可能是什么错误呢?
1
cosmain 2023-05-30 11:17:11 +08:00
Gradle project sync failed
是不是网络问题? |
2
githmb 2023-05-30 11:17:11 +08:00
跟你上不了 v2 一样的原因。毕竟安卓姓谷歌。
|
3
xloger 2023-05-30 11:17:56 +08:00
网络问题?听着不像是你的 AS 或者 Gradle 出问题,而是 Gradle 没能把你这个项目所需依赖下载下来的问题,你可以按这个思路排查一下。
|
4
KT0J 2023-05-30 11:19:16 +08:00
电摇是什么?
不过基本上就是网络问题。 |
5
hahastudio 2023-05-30 11:21:57 +08:00 1
@KT0J 我猜想说的是 Android Studio Electric Eel ,电鳗
|
6
chopin1998519 OP 网络问题? 我已经设置好 proxy 了呀。。。
|
7
qwwuyu 2023-05-30 11:30:51 +08:00
报错信息应该没看全,如果是网络问题,也会告诉你哪个下载失败了.
在失败窗口左侧多点击下找一下全部信息,在全部信息里翻找一下 Error 信息. |
8
chopin1998519 OP 请问 如果是网络问题的话, 哪里能看到日志?
|
9
aapeli 2023-05-30 11:33:06 +08:00
@chopin1998519 报错截图来一张
|
10
KT0J 2023-05-30 11:36:01 +08:00
|
11
chopin1998519 OP |
12
chopin1998519 OP |
13
ExplodingFKL 2023-05-30 11:44:00 +08:00
|
14
zhenghuiy 2023-05-30 11:50:04 +08:00
@chopin1998519 网上有相当一部分教程里的 proxy 是错的,之前被坑过。可能不设置 proxy + 开全局梯子 更简单。
|
15
chopin1998519 OP @zhenghuiy 问题是 我看不到现在是否是因为网络的原因, 没有提示。。。
|
16
ExplodingFKL 2023-05-30 12:05:49 +08:00
看你的 window 不像是 windows ,试试在 console 运行 ./gradlew clean build 看看错误信息,可以加上 --debug 参数
|
17
v2yllhwa 2023-05-30 12:19:42 +08:00 via Android
实际上 dl.google.com 国内是有服务器的,可以尝试设置下 hosts
|
18
iOCZ 2023-05-30 12:19:54 +08:00 12
你的安卓开发旅程差不多要结束了
|
19
lixuanyy 2023-05-30 12:28:05 +08:00 via iPhone 1
突然想到了之前的一个笑话,三个 G 的 hello world
|
20
chopin1998519 OP @ExplodingFKL
确实有有一堆错误。。 最后一段这样, 能看出什么吗? 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] A new daemon was started but could not be connected to: pid=DaemonInfo{pid=261152, address=[0c0205be-28f5-4060-bc75-b4f2fefe660c port:43841, addresses:[/127.0.0.1]], state=Busy, lastBusy=1685421977961, context=DefaultDaemonContext[uid=bd402a2c-565c-485a-845d-febf686b1655,javaHome=/usr/lib/jvm/java-17-oracle,daemonRegistryDir=/home/marco/.gradle/daemon,pid=261152,idleTimeout=10800000,priority=NORMAL,daemonOpts=--add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx2048m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]}, address= [0c0205be-28f5-4060-bc75-b4f2fefe660c port:43841, addresses:[/127.0.0.1]]. See https://docs.gradle.org/8.0/userguide/troubleshooting.html#network_connection for more details. 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try: 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Run with --scan to get full insights. 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Exception is: 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.launcher.daemon.client.NoUsableDaemonFoundException: A new daemon was started but could not be connected to: pid=DaemonInfo{pid=261152, address=[0c0205be-28f5-4060-bc75-b4f2fefe660c port:43841, addresses:[/127.0.0.1]], state=Busy, lastBusy=1685421977961, context=DefaultDaemonContext[uid=bd402a2c-565c-485a-845d-febf686b1655,javaHome=/usr/lib/jvm/java-17-oracle,daemonRegistryDir=/home/marco/.gradle/daemon,pid=261152,idleTimeout=10800000,priority=NORMAL,daemonOpts=--add-opens=java.base/java.util=ALL-UNNAMED,--add-opens=java.base/java.lang=ALL-UNNAMED,--add-opens=java.base/java.lang.invoke=ALL-UNNAMED,--add-opens=java.prefs/java.util.prefs=ALL-UNNAMED,--add-opens=java.base/java.nio.charset=ALL-UNNAMED,--add-opens=java.base/java.net=ALL-UNNAMED,--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED,-Xmx2048m,-Dfile.encoding=UTF-8,-Duser.country=US,-Duser.language=en,-Duser.variant]}, address= [0c0205be-28f5-4060-bc75-b4f2fefe660c port:43841, addresses:[/127.0.0.1]]. See https://docs.gradle.org/8.0/userguide/troubleshooting.html#network_connection for more details. 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:172) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:99) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:57) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:167) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.DefaultCommandLineActionFactory$ParseAndBuildAction.execute(DefaultCommandLineActionFactory.java:259) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.DefaultCommandLineActionFactory$ParseAndBuildAction.execute(DefaultCommandLineActionFactory.java:230) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.DebugLoggerWarningAction.execute(DebugLoggerWarningAction.java:82) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.DebugLoggerWarningAction.execute(DebugLoggerWarningAction.java:30) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.WelcomeMessageAction.execute(WelcomeMessageAction.java:96) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.WelcomeMessageAction.execute(WelcomeMessageAction.java:40) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.NativeServicesInitializingAction.execute(NativeServicesInitializingAction.java:44) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.NativeServicesInitializingAction.execute(NativeServicesInitializingAction.java:26) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:41) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:26) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.cli.DefaultCommandLineActionFactory$WithLogging.execute(DefaultCommandLineActionFactory.java:361) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.Main.doAction(Main.java:35) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:50) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at java.base/java.lang.reflect.Method.invoke(Method.java:568) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at java.base/java.lang.reflect.Method.invoke(Method.java:568) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.launcher.GradleMain.main(GradleMain.java:34) 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2023-05-30T12:46:17.979+0800 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at https://help.gradle.org |
21
taken 2023-05-30 12:55:35 +08:00
代理没配置好 baby
|
22
ExplodingFKL 2023-05-30 13:01:04 +08:00
@chopin1998519 你把所有代理相关的配置清除或者在执行命令的时候加上 --no-daemon 参数再看看详细结果
|
23
mineralsalt 2023-05-30 13:09:13 +08:00
网络问题, 鉴定完毕
|
24
skyinu 2023-05-30 13:16:57 +08:00
可以用阿里云的 maven 仓库试一下,可以规避网络问题
|
25
BigMikey 2023-05-30 13:38:14 +08:00
网络问题,我是全局的,所以没毛病,系统是 MacOS ,/Doge
|
26
iovekkk 2023-05-30 13:39:47 +08:00
在~/.gradle 目录下创建 init.gradle 文件
文件内容如下: allprojects { buildscript { repositories { maven { url 'https://maven.aliyun.com/repository/public/' } maven { url 'https://maven.aliyun.com/repository/google/' } maven { url "https://maven.aliyun.com/repository/gradle-plugin/"} } } repositories { maven { url 'https://maven.aliyun.com/repository/public/' } maven { url 'https://maven.aliyun.com/repository/google/' } maven { url "https://maven.aliyun.com/repository/gradle-plugin/"} } println "${it.name}: Aliyun maven mirror injected" } 创建完毕之后,重启 Android studio 即可 |
27
kaedea 2023-05-30 13:40:38 +08:00 via Android
网络问题,不仅要开 HTTP 代理,还要开 socket 代理。
|
28
ExplodingFKL 2023-05-30 13:44:38 +08:00
阿里云是个大坑 ... 而且在没有其他签名校验的情况下可能出现供应链攻击,啥时候 maven 每个文件带 gpg 签名就好了
|
29
superedlimited 2023-05-30 13:45:06 +08:00
|
30
chopin1998519 OP @iovekkk 试过了, 还是一样的错误。。
|
31
chopin1998519 OP @superedlimited 是的,
我也直接在 terminal 里用 http_proxy/ https_proxy 环境变量试过 这样设置好后,gradle 还会问我要不要把这个配置写在它自己的全局配置文件里(~/.gradle/) |
32
chopin1998519 OP @kaedea 什么意思? 我的是 clash, socks 和 http 混合端口, 都能用的
|
33
superedlimited 2023-05-30 13:48:57 +08:00
@superedlimited btw ,eel 是鳗鱼,鳐是带翅膀的魔鬼鱼
|
34
superedlimited 2023-05-30 13:51:36 +08:00
@chopin1998519 A new daemon was started but could not be connected to: pid=DaemonInfo{pid=261152, address=[0c0205be-28f5-4060-bc75-b4f2fefe660c port:43841, addresses:[/127.0.0.1]], state=Busy, lastBusy=1685421977961, context=DefaultDaemonContext[uid=bd402a2c-565c-485a-845d-febf686b1655
你点一下下面那个 check connection 按钮试一试 |
35
iovekkk 2023-05-30 13:52:42 +08:00
@chopin1998519 我这种方法不需要配置代理,设置代理反而可能会有问题
|
36
chopin1998519 OP @iovekkk 我知道, 用阿里云关闭代理了, 还是一样。。。哭死
|
37
chopin1998519 OP |
38
chopin1998519 OP |
39
superedlimited 2023-05-30 14:11:38 +08:00 1
你的网络设置,有设置 nat masquerade 吗?
We have observed this can occur when network address translation (NAT) masquerade is used. When NAT masquerade is enabled, connections that should be considered local to the machine are masked to appear from external IP addresses. Gradle refuses to connect to any external IP address as a security precaution. The solution to this problem is to adjust your network configuration such that local connections are not modified to appear as from external addresses. You can monitor the detected network setup and the connection requests in the daemon log file ($GRADLE_USER_HOME/daemon/<Gradle version>/daemon-<PID>.out.log). @chopin1998519 |
40
CharmingCheung 2023-05-30 14:12:50 +08:00
看日志像是 Gradle daemon 进程出问题。问 ChatGPT:
检查 Gradle 版本:确保你使用的 Gradle 版本与 Android Studio 和你的项目配置是兼容的。如果不确定,你可以尝试升级到最新版本。 增加内存分配:Gradle 守护进程可能需要更多的内存。你可以尝试在 gradle.properties 文件中增加分配给 Gradle 的内存,例如:org.gradle.jvmargs=-Xmx2048m 分配 2GB 内存给 Gradle 。 停止现有的 Gradle 守护进程:可能是已有的 Gradle 守护进程导致了问题。你可以试试运行./gradlew --stop 命令,以停止所有正在运行的 Gradle 守护进程,然后再次构建你的项目。 检查网络连接:你的错误日志中提到了一个关于网络连接的 URL 。如果你在一个有网络限制的环境下(如公司网络或者校园网),可能需要检查你的网络连接或者代理设置。 如果这些解决方案都没有解决你的问题,你可以尝试根据错误日志提示的运行--scan 命令(例如./gradlew build --scan )来获取更详细的错误信息,这可能会帮助你更准确地找到问题所在。 |
41
mineralsalt 2023-05-30 14:22:19 +08:00
@chopin1998519 #38 这里设置完代理之后, 需要重启软件
|
42
chopin1998519 OP @superedlimited
Oh! My! God!!! 我这个台式机, 用的是 wifi 访问外网, 然后以太网连接的是一个交换机, 有一些其它设备挂在上面通过台式机上网,所有 nat 。。。。。。。。 现在临时删掉了 iptables 规则, 至少目前可以编译了!!!! 太太太感谢了! |
43
chopin1998519 OP @superedlimited 您这个是问的谁?
|
44
flashdiko 2023-05-30 14:43:13 +08:00
只需要设置 init.gradle, 其余设置默认就行,不用网络代理
|
45
psklf 2023-05-30 14:56:49 +08:00
你的安卓开发旅程差不多要结束了
拜中国网络封锁所赐 |
46
chopin1998519 OP @flashdiko 亲测无效。。。
|
47
superedlimited 2023-05-30 14:58:14 +08:00
#42 @chopin1998519
是你上面那个 log 里的地址,有说到这个 https://docs.gradle.org/8.0/userguide/troubleshooting.html#network_connection |
48
chopin1998519 OP @psklf 目前可以了,感谢 @mineralsalt
|
49
maswang 2023-05-30 15:00:24 +08:00
仿佛看到了十年前的自己
|
50
lijunjieone 2023-05-30 15:22:26 +08:00
./gradlew app:asD --info 试试用命令是不是可以看到更详细的错误。
|
51
aerzha 2023-05-30 15:35:23 +08:00
gradle 现在还需要开代理么
|
52
Parva 2023-05-30 15:49:03 +08:00
写了两年 android 没遇过这种错误,上面一堆人跟我一样想着代理哪里没设置好。
但果然还是大佬才能看出错误信息里的关键部分,找出真正原因和解决办法。 |
53
hfl1995 2023-05-30 15:53:45 +08:00
现在 android studio 一般都不需要挂代理了,除非有些远程库完全被墙
|
54
Vclow 2023-05-30 15:54:47 +08:00 1
49 年入国军吗?
|
55
Resurgam 2023-05-30 16:24:05 +08:00
考虑下转行吧,我干了 8 、9 年了,真没啥好干的了
|
56
736531683 2023-05-30 16:48:17 +08:00
我大学舍友上完安卓课也没跑起来 hello world ,国内用 gradle 这个网络确实蛋疼。
|
57
dnzh1wei 2023-05-30 16:52:55 +08:00
爱学习值得鼓励,加油!想到了当时我在大学的时候准备自学 android 的热血,![Snipaste_2023-05-30_16-50-28.png]( https://cdn.dnovo.cn/2023/05/30/6475b937924e0.png)
|
58
dnzh1wei 2023-05-30 16:54:01 +08:00
如今是一名光荣的大前端=-=
|
59
honhon 2023-05-30 17:34:29 +08:00
android 构建不需要配置代理,不过依赖下载速度稍微慢点,要加速可以配置仓库镜像地址
|
60
fresco 2023-05-30 18:59:32 +08:00
纯纯的网络问题,挺难受的
|
61
wasd6267016 2023-05-30 23:13:48 +08:00
这是会提问的 不知道还有多少新程序员卡死在网络这一步……
想起了当年也因为网络问题整到崩溃 加油吧楼主 |
62
ShayneWang 2023-05-30 23:33:25 +08:00
接手一个老的 Android 项目 真是操蛋
|
63
anan1231230 2023-05-31 09:22:15 +08:00
听哥一句劝,移动互联网走下坡路了,java 后台更稳一些
|
64
chopin1998519 OP |
65
kalixi 2023-05-31 09:37:27 +08:00
代理没配置好 baby
|
66
Maiiiiii 2023-05-31 09:49:05 +08:00
现在一般不需要配置代理了,可能某些远程仓库会拉不到。不像以前,没梯子 gradle 都下不了
|
67
DubheBroken 2023-06-01 07:31:40 +08:00
gradle 的代理需要单独配置,你改 Android Studio 的代理设置和改系统代理设置都是没效果的。
打开你的项目,找到最外层的 gradle.properties 这个文件,在末尾加上以下语句: systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyPort=10800 第一个=后面是代理地址,第二个=后面是端口号,根据你自己的情况改一下。 重新同步就行了。 |