Fix Android Studio Gradle Build Stuck — 7 Quick Fixes (Offline, Cache, Proxy)

Last Updated: · Complete guide to fix Android Studio Gradle build hanging issues

Quick Summary

Gradle build gets stuck most often due to offline mode, network/proxy issues, or cache problems.

  • Turn Offline mode OFF
  • Stop running Gradle daemons
  • Clear Gradle caches and restart the IDE
  • Verify network and proxy settings

Identifying the Problem

You may be experiencing a Gradle build hang if you notice these symptoms:

  • "Gradle build running..." message won't disappear
  • Build progress stuck in the bottom Build tab
  • Build appears to run forever or never completes
  • Low CPU usage but Android Studio becomes unresponsive
💡 Note: Build times vary by hardware, project size, plugins, and caches. If builds suddenly become much slower or never complete, use Build Analyzer to investigate.

Understanding the Root Causes

1. Network Connection Issues

Gradle hangs when it can't download dependency libraries due to network blocks or proxy configuration problems.

2. Corrupted Gradle Cache

Old or corrupted cache files can conflict and prevent the build process from completing normally.

3. Offline Mode Enabled

When Offline mode is active, Gradle can't download new dependencies, causing builds to stall.

4. Gradle Daemon Conflicts

Gradle daemon processes from previous builds that didn't terminate properly can conflict with new builds.

Step-by-Step Solutions

Method 1: Turn Off Offline Mode

  1. Open the Gradle tool window (right toolbar) and make sure Toggle Offline Mode is OFF.
  2. Alternatively, go to Settings/Preferences → Build, Execution, Deployment → Gradle and uncheck Offline work (if present).
  3. Click Sync Project with Gradle Files.
  4. CLI check: compare ./gradlew build vs ./gradlew build --offline.
Android Studio Gradle settings on macOS showing the Offline work checkbox unchecked

Screenshot: Android Studio Gradle tool window showing the Offline mode toggle (macOS/Windows)
Source: Stack Overflow

Method 2: Stop All Gradle Daemons

Run this command in your terminal:

./gradlew --stop

Windows users:

gradlew.bat --stop

Check running daemons:

./gradlew --status

Method 3: Clear Gradle and IDE Caches

Gradle cache locations:

C:\Users\[username]\.gradle\caches
~/.gradle/caches

IDE cache: Use File → Invalidate Caches / Restart in Android Studio

  1. Close Android Studio completely
  2. Delete the caches folder from the path above
  3. Restart Android Studio
  4. Run File → Sync Project with Gradle Files

Method 4: Configure Network and Proxy Settings

If you're on a corporate or school network, you may need proxy configuration. Set this up in both IDE settings (Appearance & Behavior → System Settings → HTTP Proxy) and gradle.properties:

systemProp.http.proxyHost=[proxy address]
systemProp.http.proxyPort=[port number]
systemProp.https.proxyHost=[proxy address]
systemProp.https.proxyPort=[port number]

Method 5: Clean and Rebuild Project

  1. Run Build → Clean Project
  2. After completion, run Build → Rebuild Project

Preventing Future Issues

Regular Maintenance Tips

  • Only clear Gradle cache when problems occur
  • Maintain stable network connectivity
  • Remove unnecessary Gradle plugins
  • Keep Gradle version compatible with your Android Gradle Plugin (AGP)

Updating Gradle Version

Check the distributionUrl in gradle/wrapper/gradle-wrapper.properties:

distributionUrl=https\://services.gradle.org/distributions/gradle-x.x-bin.zip

Use a Gradle version compatible with your Android Gradle Plugin (AGP). (Refer to the official AGP–Gradle compatibility table)

Advanced Solutions

Increase JVM Memory Allocation

Add to gradle.properties:

org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=512m

Enable Parallel Builds (Optional)

# Only effective for multi-module projects
org.gradle.parallel=true

Force Refresh Dependencies via Command Line

./gradlew clean build --refresh-dependencies

This forces Gradle to re-download all dependencies.

⚠️ Important: Advanced settings may vary depending on your project environment. Always backup before applying changes.

Conclusion

Most Gradle build hanging issues can be resolved by checking cache/network settings and disabling Offline mode. Try the steps above in order.

🔗 Related Resources

Was this guide helpful? If the problem persists, check the official Android Studio support page.

Post a Comment

0 Comments