Android Studio 3.1.2在Ubuntu16.04上Gradle同步失败:读取超时求助
Hey there, since you've already tried setting up HTTP proxies and adding other repositories without luck, let's dive into more targeted fixes for this timeout issue—especially since Android Studio 3.1.2 has some specific compatibility quirks with Gradle and remote repos:
1. Optimize Repository Configs with Reliable Domestic Mirrors
You might have added domestic repos before, but let's make sure they're prioritized correctly and cover all necessary sources. Replace or reorder the repositories in your project-level build.gradle like this:
buildscript { repositories { maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } // Keep google()/jcenter() only if you need them, but put mirrors first // google() // jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.1.2' // Match your AS version exactly } } allprojects { repositories { maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/jcenter' } maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } } }
Pro tip: Android Studio 3.1.2 pairs with Gradle 4.4—don't upgrade this randomly, as mismatched versions often cause sync failures.
2. Extend Gradle Timeout Settings
Default timeouts are often too short for unstable networks. Add these lines to your project's gradle.properties file:
org.gradle.jvmargs=-Xmx1536m org.gradle.parallel=true # Increase timeout values gradle.connection.timeout=100000 gradle.daemon.idletimeout=3600000
You can also adjust the IDE-level timeout: Go to File > Settings > Build, Execution, Deployment > Build Tools > Gradle and set "Build timeout" to 300 seconds or longer.
3. Troubleshoot Proxy Configurations (Common Pitfalls)
If you're using a proxy, double-check these easy-to-miss details:
- Does your proxy support HTTPS? Most Android repos use HTTPS, so an HTTP-only proxy will fail silently.
- Disable "Auto-detect proxy settings" in File > Settings > Appearance & Behavior > System Settings > HTTP Proxy—manual proxies conflict with auto-detection.
- Test the proxy in your browser first: Try accessing
https://dl.google.com/dl/android/maven2/index.htmlthrough the proxy. If it loads, the issue is likely in AS's proxy setup, not the proxy itself. - Try disabling the proxy entirely if you can access domestic mirrors directly—sometimes proxies introduce more latency than they solve.
4. Manually Download Gradle to Bypass Network Issues
Auto-downloading Gradle often fails with timeouts. Here's how to do it manually:
- Check your project's
gradle/wrapper/gradle-wrapper.propertiesfor the required version (e.g.,distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip). - Download the zip file from a reliable source (like the official Gradle site or a domestic mirror).
- Place the zip in your local Gradle cache directory:
- Windows:
C:\Users\<YourUsername>\.gradle\wrapper\dists\gradle-4.4-all\<RandomFolderName> - Mac/Linux:
~/.gradle/wrapper/dists/gradle-4.4-all/<RandomFolderName>
- Windows:
- Restart Android Studio and trigger a Gradle sync.
5. Clear Caches and Restart Android Studio
Corrupted caches can cause all sorts of weird sync issues:
- Go to File > Invalidate Caches / Restart and select "Invalidate and Restart" to clear IDE caches.
- Manually delete the
.gradleandbuildfolders in your project root, then sync again.
6. Rule Out Network Environment Restrictions
- If you're on a VPN, try turning it off—some VPNs throttle or block connections to Maven repos.
- Corporate networks often have firewalls that block external repos. Check with your IT team to whitelist domains like
maven.aliyun.com,dl.google.com, andservices.gradle.org. - Switch to a mobile hotspot temporarily to see if the issue is with your local network.
If none of these work, sharing the full sync log (beyond just "read time out") would help narrow down the exact problem—there might be specific dependencies failing to download that we can target.
内容的提问来源于stack exchange,提问作者YPO

