You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Git克隆项目后Gradle构建出现连接重置超时问题求助

Fixing Gradle "Connection Reset" Error During Build (For Android Newbies)

Hey there! Let's work through this Gradle issue together—since this is your first Android project, I’ll keep everything simple and actionable, no jargon overload.

First, let’s break down why this happens: That "connection reset" error usually pops up when your internet cuts out mid-download, or Gradle’s default repository is slow/unstable from your location. Since you’ve already tried re-cloning the project and deleting the Gradle folder, let’s try these targeted fixes:

1. Switch to a Faster Maven Mirror

Gradle pulls dependencies from Maven Central by default, which can be sluggish in some regions. Adding a domestic mirror will speed up downloads and reduce connection drops:

  • Open your project’s root build.gradle file (the one in the main project folder, not the app subfolder).
  • Look for the repositories blocks (there might be one under buildscript and another under allprojects).
  • Add a mirror URL before the default repos. For example:
repositories {
    maven { url 'https://maven.aliyun.com/repository/public' }
    mavenCentral()
    google()
}

This tells Gradle to try the faster mirror first, which should be more stable.

2. Increase Gradle’s Timeout Limits

Sometimes the download takes longer than Gradle expects, leading to a timeout that looks like a connection reset. Let’s extend the wait time:

  • Create or edit the gradle.properties file in your project’s root folder (if it doesn’t exist, just make a new text file with this name).
  • Add these lines:
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m
org.gradle.connection.timeout=300000
org.gradle.daemon=true
org.gradle.parallel=true

The connection.timeout sets the wait time to 5 minutes (300000 milliseconds), giving large downloads more time to finish.

3. Check Your Network Stability

  • Stick to a stable Wi-Fi or wired connection—public networks are often flaky and can interrupt downloads mid-process.
  • If you’re using a VPN, try turning it off (or switching to a different one) since some VPNs block access to Maven repositories.

4. Manually Download Gradle (Last Resort)

If Gradle itself fails to download, grab it manually:

  • Check the required Gradle version in your project’s gradle/wrapper/gradle-wrapper.properties file (look for the distributionUrl line).
  • Copy that URL, download the zip file in your browser, and save it to your local Gradle cache folder:
    • Windows: C:\Users\<YourUsername>\.gradle\wrapper\dists\<GradleVersion>\<RandomFolder>
    • Mac/Linux: ~/.gradle/wrapper/dists/<GradleVersion>/<RandomFolder>
  • Unzip the file there, then try building your project again.

Quick Fix for XML Preview Issues

Once the build succeeds, if the XML preview still doesn’t show up, click the "Refresh" button in the top-right corner of the preview panel. Sometimes it just needs a quick refresh after a successful build.

I know this is frustrating for your first project—take it step by step, and don’t hesitate to ask your team members for a hand if you get stuck on any of these steps!

内容的提问来源于stack exchange,提问作者harlekurt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:59:02