What Does the Gradle Offline Mode Error Mean
The Gradle Offline Mode error occurs when Android Studio is running in offline mode, but Gradle cannot find the required dependencies in the local cache. As a result, the project build fails with a message similar to:
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find com.android.tools.build:gradle:8.2.0.
Required by:
project :app
This mode is useful for working without an internet connection, but it requires that all artifacts (libraries, plugins) have been pre-downloaded. The error appears when you first run a new project, after clearing the cache, or when changing dependency versions.
Causes
- Offline mode is enabled in Gradle settings β Gradle ignores online repositories and looks for artifacts only in the local cache.
- Missing cached dependencies β for example, after installing Android Studio or when using a new computer.
- Corrupted local Gradle cache β files in the cache (
~/.gradle/caches) are damaged or incomplete. - Dependency version conflict β
build.gradlespecifies a library version that is not present in the local cache. - Incorrect proxy settings β Gradle cannot connect to repositories due to a firewall block or misconfigured proxy.
Solutions
Solution 1: Disable Offline Mode
The simplest solution is to disable offline mode in Android Studio settings.
- Open File β Settings (on macOS: Android Studio β Preferences).
- Navigate to Build, Execution, Deployment β Gradle.
- Under Gradle settings, uncheck Offline work.
- Click OK.
- Sync the project by clicking Sync Project with Gradle Files (the elephant icon in the toolbar).
After this, Gradle will be able to download missing dependencies from the internet.
Solution 2: Force Project Sync
If disabling the mode didn't help, perform a forced sync with a cleanup of previous configurations.
- Ensure Offline Mode is disabled (see Solution 1).
- Close the project (File β Close Project).
- Delete the
.gradlefolder in your project's root directory (it will be recreated). - Reopen the project.
- Click Sync Project with Gradle Files.
- Wait for the dependencies to finish downloading.
β οΈ Important: Deleting the
.gradlefolder in the project does not affect the global cache (~/.gradle), so it won't harm other projects.
Solution 3: Clear the Global Gradle Cache
Sometimes the issue lies in a corrupted global cache. Clearing it will force Gradle to re-download all dependencies.
- Close Android Studio.
- Open a terminal (cmd, PowerShell, or Bash).
- Run the command:
For Windows, use:gradle --stop rm -rf ~/.gradle/caches/gradle --stop rd /s /q %USERPROFILE%\.gradle\caches - Restart Android Studio.
- Open the project and sync it.
π‘ Tip: If you have multiple projects, they will start downloading dependencies again, which will take time depending on your internet speed.
Solution 4: Check Proxy and Network Settings
Gradle may fail to connect to repositories due to network or proxy issues.
- Check your internet connection β open a browser and visit
https://repo.maven.apache.org. - In Android Studio, open File β Settings β Appearance & Behavior β System Settings β HTTP Proxy.
- Select No proxy (if on a local network) or enter correct proxy parameters.
- Click Check connection and enter
https://repo.maven.apache.orgβ you should see "Connection successful". - If using a corporate proxy, ensure settings are specified in
gradle.properties(in the~/.gradle/folder or project):systemProp.http.proxyHost=your_proxy systemProp.http.proxyPort=port systemProp.https.proxyHost=your_proxy systemProp.https.proxyPort=port - Restart Android Studio and sync the project.
Solution 5: Update Gradle and Android Gradle Plugin
Outdated versions of Gradle or AGP may malfunction with offline mode.
- Open the
build.gradlefile (Project level). - Check the versions:
dependencies { classpath 'com.android.tools.build:gradle:8.2.0' // AGP version } - In the
gradle/wrapper/gradle-wrapper.propertiesfile, specify the current Gradle version:distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip - Sync the project β Android Studio will prompt you to update if necessary.
- After updating, try building again.
Prevention
- Do not enable Offline Mode unless necessary β keep it disabled so Gradle can automatically update dependencies.
- Regularly update dependencies β use current library versions in
build.gradleto avoid conflicts. - Use a stable internet connection β when working with new projects, ensure you have network access.
- Do not manually delete files from the Gradle cache β this can cause corruption. Use Android Studio commands or settings for cleanup.
- Configure caching in a corporate network β if you're a developer at a company, ask your administrator to set up a local repository (Nexus, Artifactory) to reduce reliance on the internet.
These measures will help prevent the Gradle Offline Mode error from recurring and ensure stable project builds.