Android Studio设置Gradle离线模式报错,如何解决无可用缓存版本问题?
Got it, let's fix this Gradle offline mode issue step by step. The error message is pretty clear—your local Gradle cache doesn't have the com.android.tools.build:gradle:3.1.2 plugin stored yet, so when you switch to offline mode, Android Studio can't pull it from anywhere to build your project. Here's how to resolve it:
How to Fix "No cached version of com.android.tools.build:gradle:3.1.2 available for offline mode"
Step 1: Disable Offline Mode First
We need to let Android Studio download the missing dependency before we can use offline mode. Here's how to turn it off:
- Open your project in Android Studio.
- Go to File > Settings (on Mac, it's Android Studio > Settings).
- Navigate to Build, Execution, Deployment > Build Tools > Gradle.
- Uncheck the Offline work checkbox (it’s near the bottom of the settings page).
- Click Apply then OK to save changes.
Step 2: Sync Your Project to Download the Missing Plugin
Now trigger a Gradle sync to grab the 3.1.2 version of the Android build plugin:
- Look for the Sync Project with Gradle Files button in the top toolbar—it’s the icon with two arrows circling each other.
- Click it and wait for the sync to finish. Android Studio will download the required plugin and its dependencies to your local cache. You’ll see progress in the bottom status bar.
Step 3: Re-enable Offline Mode
Once the sync completes successfully, you can switch back to offline mode to speed up future builds:
- Return to the same Gradle settings page (File > Settings > Build, Execution, Deployment > Build Tools > Gradle).
- Check the Offline work checkbox again.
- Click Apply and OK.
Bonus Troubleshooting Tips (If the Above Doesn’t Work)
If you still run into issues, try these fixes:
- Double-check your build.gradle file: Open your project-level
build.gradleand confirm the lineclasspath 'com.android.tools.build:gradle:3.1.2'has no typos (version number is exactly correct). - Invalidate Caches and Restart: Go to File > Invalidate Caches... > Invalidate and Restart. This clears corrupted cache files that might be blocking the download.
- Verify your internet connection: Make sure you have a stable connection during the initial sync—partial downloads can leave broken cache files that cause errors later.
内容的提问来源于stack exchange,提问作者Jora




