How to Clear Gradle Cache in Android Studio?
As an Android developer, you might have encountered issues with Gradle, the build system used by Android Studio to compile and build Android applications. Gradle cache can sometimes become corrupted or outdated, leading to compilation errors, build failures, or even Android Studio crashes. In this article, we will explore the ways to clear Gradle cache in Android Studio and resolve common issues related to Gradle caching.
Why Clear Gradle Cache?
Before we dive into the process of clearing Gradle cache, let’s understand why it’s essential to do so. Gradle cache is used to store the results of Gradle tasks, such as compiling, building, and packaging your Android application. This cache is meant to speed up the development process by reusing the cached results instead of re-running the tasks every time you build your project. However, if the cache becomes outdated or corrupted, it can cause issues with your application’s build process.
How to Clear Gradle Cache in Android Studio?
To clear Gradle cache in Android Studio, you can follow these steps:
Method 1: Clear Gradle Cache from the UI
- Open Android Studio and navigate to the File menu and select Invalidate Caches / Restart.
- In the Invalidate Caches & Restart dialog box, click on Invalidate and Restart.

Method 2: Clear Gradle Cache from the Command Line
- Open a terminal window and navigate to your project directory.
- Run the following command:
./gradlew --stopto stop the Gradle daemon. - Run the following command:
./gradlew --blank-caches --refresh-dependent-dialoguesto clear the Gradle cache and refresh the dependent daemons.
Method 3: Clear Gradle Cache using Android Studio Settings
- Open Android Studio and navigate to Settings (or Preferences on Mac) by pressing Ctrl + Shift + O (or Cmd + Shift + O on Mac).
- In the Settings window, navigate to Build, Execution, Deployment > Gradle.
- Check the Clear Gradle cache checkbox.
When to Clear Gradle Cache?
Clearing Gradle cache can be useful in the following scenarios:
- After Upgrading Android Studio or Gradle: When you upgrade Android Studio or Gradle, it’s a good idea to clear the Gradle cache to ensure a fresh start.
- After Changing Project Structure: If you modify your project structure, such as adding or removing modules, clearing Gradle cache can help ensure that the changes are properly reflected in your build.
- After Resolving Conflicting Library Dependencies: If you encounter issues with conflicting library dependencies, clearing Gradle cache can help resolve the conflicts.
- When Unresolved Dependencies Exist: If you encounter unresolved dependencies, clearing Gradle cache can help resolve the issues.
Common Gradle Cache-related Issues
- Gradle build fails with "Failed to find or load main manifest" error: Clearing Gradle cache can resolve this issue by redoing the assembly of the project.
- Gradle build fails with "Error: Module ‘abc’ not found" error: Clearing Gradle cache can resolve this issue by refreshing the dependency graph.
- Gradle build fails with "Cannot resolve ‘com.example:module:1.0.0’" error: Clearing Gradle cache can resolve this issue by re- resolving dependencies.
Conclusion
Clearing Gradle cache in Android Studio can help resolve various issues related to Gradle caching. By following the methods outlined above, you can effectively clear Gradle cache and ensure that your Android application builds and runs smoothly. Remember to clear Gradle cache in scenarios like upgrading Android Studio or Gradle, changing project structure, resolving conflicting library dependencies, or when unresolved dependencies exist. By doing so, you can ensure that your Android application is built correctly and efficiently.
