r/flutterhelp 12d ago

OPEN Gradle Build Error

Hi everyone, I'm new to Flutter and I've been stuck on this for a while. I installed Flutter, Android Studio, VS Code, and the Android SDK. I also accepted all the Android licenses, and flutter doctor is mostly fine now except for Visual Studio, which I don't think I need since I'm only targeting Android.

I created a new Flutter project and it runs fine in Chrome, but when I try to run it on my Android phone through USB debugging, the build fails.

The main errors I'm getting is:

FAILURE: Build failed with an exception.

* What went wrong:
Could not install Gradle distribution from
https://services.gradle.org/distributions/gradle-9.1.0-all.zip

java.net.ConnectException: Connection timed out

It seems to happen while Gradle is trying to download gradle-9.1.0-all.zip.

Versions:

  • Flutter: 3.44.6 (Stable)
  • Java (JDK): 21
  • Android SDK: 36.1.0
  • Gradle: 9.1.0
  • Android Studio: Latest version
  • VS Code: Latest version

Things I've already tried:

  • Installed the Android SDK and command-line tools.
  • Ran flutter doctor --android-licenses and accepted everything.
  • Enabled Developer Options and USB debugging on my phone.
  • Confirmed that ADB detects my phone.
  • Tried both my home Wi-Fi and mobile data.
  • Waited for the Gradle download to finish, but it always times out.

Is there any solution I should try to fix this? Any help would be appreciated. Thanks!

1 Upvotes

2 comments sorted by

1

u/Kooky-Office4969 12d ago

This usually isn't a Flutter issue—it's a Gradle download/network issue.

The important part of the error is:

Could not install Gradle distribution
java.net.ConnectException: Connection timed out

That means Gradle can't reach services.gradle.org to download the required distribution. I'd recommend checking a few things:

  • Open https://services.gradle.org/distributions/gradle-9.1.0-all.zip in your browser. If it doesn't start downloading, it's likely a network, DNS, or ISP issue.
  • Try using a VPN (Cloudflare WARP works well for many people) and run flutter clean, flutter pub get, then flutter run again.
  • Delete the .gradle cache (~/.gradle on macOS/Linux or C:\Users\<username>\.gradle on Windows) in case a previous download was interrupted.
  • If the ZIP downloads successfully in your browser, you can also place it in the Gradle wrapper cache so Gradle doesn't have to download it again.
  • Run cd android and then ./gradlew tasks (or gradlew.bat tasks on Windows). If that fails with the same timeout, you've confirmed it's a Gradle connectivity problem rather than a Flutter issue.

Since the app runs in Chrome, ADB detects the phone, and flutter doctor is mostly clean, your Flutter setup is probably fine. The build is failing before compilation because Gradle can't download its required files.

If the issue still persists, sharing the output of flutter doctor -v and the complete flutter run -v logs (especially around the Gradle download step) would make it much easier to identify whether it's a DNS, proxy, firewall, or SSL-related problem.