Linux Mint模拟器中Flutter项目Gradle超时运行失败求助
Hey there! Let's work through this Gradle timeout and file lock issue you're hitting on Linux Mint Tina with your first Flutter project. I've dealt with similar roadblocks before, so here are some practical, step-by-step fixes to get your app running:
1. Release Gradle File Locks & Clear Cached Distributions
The "exclusive access" error usually means a leftover Gradle process is holding a lock on the file. Let's kill those processes and clean up the problematic cache:
- First, terminate all background Gradle processes:
pkill -f gradle - Then delete the locked Gradle distribution directory:
rm -rf /home/simo/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb/ - Head back to your Flutter project root and run
flutter runagain—this will trigger a fresh download of the Gradle package.
2. Manually Download & Install the Gradle Package
Network latency or restrictions on Linux might be causing the timeout. Skip the auto-download by getting the package manually:
- Download the exact version mentioned in your error:
gradle-5.6.2-all.zip - Create the target directory if it doesn't exist:
mkdir -p /home/simo/.gradle/wrapper/dists/gradle-5.6.2-all/9st6wgf78h16so49nn74lgtbb/ - Move the downloaded zip file into that directory.
- Run
flutter runagain—Gradle will now unpack the local file instead of downloading it.
3. Switch to Domestic Gradle Repositories
Foreign repositories are often slow from China. Update your project's Gradle config to use domestic mirrors (like Alibaba's):
Open your project's android/build.gradle file and replace the repositories blocks with:
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 other existing buildscript content intact } 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' } } }
Save the file and re-run flutter run—this will speed up dependency downloads drastically.
4. Extend Gradle Timeout Limits
Sometimes the default timeout is too short for slow networks. Increase it in your project's android/gradle.properties file:
Add these lines at the bottom:
# Extend download timeout to 5 minutes (300,000 milliseconds) android.gradle.plugin.download.timeout=300000 org.gradle.jvmargs=-Xmx1536M org.gradle.daemon=true
This gives Gradle more time to complete downloads without timing out.
5. Fix Permissions for the .gradle Directory
Linux file permission issues can block Gradle from accessing its files. Ensure your user owns the .gradle directory:
sudo chown -R simo:simo /home/simo/.gradle/ chmod -R 755 /home/simo/.gradle/
This grants read/write access to your user, eliminating permission-related locks.
6. Restart Everything (Yes, Really!)
Occasionally, stale processes or cached state can cause weird issues. Fully close Android Studio, kill any leftover Java/Gradle processes, then restart your Linux Mint system. Open your project again and try flutter run once more.
If none of these work, you can also try updating Flutter to the latest stable release with flutter upgrade or double-checking that your Android SDK components are fully installed in Android Studio's SDK Manager.
内容的提问来源于stack exchange,提问作者Simon

