If you’re developing Android apps and suddenly hit a “Connection timed out” error while syncing your project or accessing dependencies, it can completely stall your workflow. This error usually occurs when Android Studio can’t connect to required servers, such as Maven repositories or Google services. Let’s walk through how to fix this issue step-by-step, based on real-world experience and practical solutions.


🔍 Why the “Connection Timed Out” Error Happens

The error typically appears in Gradle sync, SDK downloads, or when accessing remote repositories. Common reasons include:

  • Slow or unstable internet connection
  • Proxy or firewall blocking connections
  • Misconfigured Gradle settings
  • Android Studio using IPv6 instead of IPv4
  • Outdated or missing SSL certificates

Let’s troubleshoot and resolve each of these potential causes.


✅ Step-by-Step Fixes

1. Check Internet and Disable VPN/Firewall

First, rule out basic issues.

  • Make sure your internet connection is stable.
  • Disable any active VPN or firewall temporarily.
  • Restart your router or switch networks if possible.

2. Use HTTP Instead of HTTPS for Repositories

Sometimes HTTPS connections are blocked. Switch to HTTP in your Gradle configuration.

Open your build.gradle (project level) file and modify your repositories:

allprojects {
    repositories {
        maven {
            url "http://maven.google.com"
        }
        maven {
            url "http://repo.maven.apache.org/maven2"
        }
        google()
        jcenter()
    }
}

⚠️ Only do this temporarily while troubleshooting. Use HTTPS in production for security.


3. Set Gradle to Use IPv4

Android Studio or Gradle may default to IPv6, which can cause timeouts on some networks.

Add the following in your gradle.properties file:

org.gradle.jvmargs=-Djava.net.preferIPv4Stack=true

This forces Gradle to use IPv4 for all network communications.


4. Increase Gradle Timeout Settings

If your network is slow, increase the timeout limits so that Gradle waits longer before throwing an error.

Add this to gradle.properties:

systemProp.gradle.internal.http.connectionTimeout=60000
systemProp.gradle.internal.http.socketTimeout=60000

That sets both timeouts to 60 seconds.


5. Configure Android Studio Proxy Settings

If you’re behind a corporate proxy or firewall, you must configure the proxy in Android Studio correctly.

  • Go to File > Settings > Appearance & Behavior > System Settings > HTTP Proxy
  • Choose Manual Proxy Configuration
  • Enter your host and port
  • Test the connection to make sure it works

6. Manually Sync Dependencies

Sometimes automatic sync fails, but manual sync might work.

  • Open Terminal inside Android Studio
  • Run:
./gradlew build --refresh-dependencies

This forces Gradle to redownload all dependencies.


7. Update Android Studio and SDK Tools

An outdated Android Studio or SDK Manager can cause compatibility issues.

  • Go to Help > Check for Updates
  • Update Android Studio to the latest stable version
  • Open SDK Manager and update all available packages

Official download: Android Studio


8. Check hosts File and DNS

Sometimes custom entries in your hosts file can block connections.

  • Open /etc/hosts (Linux/macOS) or C:\Windows\System32\drivers\etc\hosts (Windows)
  • Make sure there are no entries blocking domains like google.com, maven.google.com, etc.

Also, try changing your DNS to Google DNS (8.8.8.8, 8.8.4.4) in your network settings.


🛠️ Bonus Tip: Use Offline Mode in Emergencies

If you’re stuck and just need to compile your app with existing dependencies:

  • Go to File > Settings > Build, Execution, Deployment > Gradle
  • Check Offline work

This disables remote lookups temporarily and uses only cached artifacts.


Final Thoughts

“Connection timed out” errors in Android Studio are frustrating but solvable. With the right combination of network tweaks, Gradle adjustments, and system configurations, you can get back to building your app without delay.

Keep Android Studio updated and consider exporting your environment setup to a backup script or configuration file. That way, if something breaks again, you’re ready to fix it fast.


Related Links

Stay focused, code smart, and build something amazing.

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *