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
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
- Open the Gradle tool window (right toolbar) and make sure Toggle Offline Mode is OFF.
- Alternatively, go to Settings/Preferences → Build, Execution, Deployment → Gradle and uncheck Offline work (if present).
- Click Sync Project with Gradle Files.
- CLI check: compare
./gradlew buildvs./gradlew build --offline.
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
- Close Android Studio completely
- Delete the
cachesfolder from the path above - Restart Android Studio
- 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
- Run Build → Clean Project
- 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.
Conclusion
🔗 Related Resources
- Official Android Studio Build System Guide
- Gradle CLI Reference
- Gradle Daemon Management
- Android App Run and Debug Guide
- Build Analyzer for Troubleshooting
Was this guide helpful? If the problem persists, check the official Android Studio support page.
0 Comments