1

My project has a dependency on an .aar file located remotely.

Android Studio keeps a copy of this file in my ./gradle/caches directory

When I clean and re-build the project, the file is not refreshed.

How can I force Android Studio to reload the archive from the remote location ?

Or is it possible to disable the gradle cache for a specific file ?

EDIT: I'd like to force a refresh of a specific file, not of the whole cache => This question is not a duplicate of How to clear gradle cache?

matdev
  • 4,115
  • 6
  • 35
  • 56
  • Possible duplicate of [How to clear gradle cache?](https://stackoverflow.com/questions/23025433/how-to-clear-gradle-cache) – Arash Hatami Jan 02 '18 at 10:38
  • 1
    I read that already, it takes too long to clear and rebuild the whole cache, hence my question – matdev Jan 02 '18 at 11:32

1 Answers1

2

You can disable caching in ~/.gradle/gradle.properties :

org.gradle.caching=false

Also you can define a task to do that :

task('clearDomainCache', type: Delete, group: 'Utilities',
      description: "Deletes any cached artifacts with the domain of com.myCompany in the Gradle or Maven2 cache directories.") doLast {
   def props = project.properties
   def userHome = System.getProperty('user.home')
   def domain = props['domain'] ?: 'com.myCompany'
   def slashyDomain = domain.replaceAll(/\./, '/')
   file("${userHome}/.gradle/cache").eachFile { cacheFile ->
      if (cacheFile.name =~ "^$domain|^resolved-$domain") delete cacheFile.path
      if (cacheFile.name =~ "^*.aar") delete cacheFile.path
   }
   delete "${userHome}/.m2/repository/$slashyDomain"
}
hb0
  • 3,350
  • 3
  • 30
  • 48
Arash Hatami
  • 5,297
  • 5
  • 39
  • 59
  • I've added org.gradle.caching=false to my gradle.properties file and when I build, an old version of the archive reappears in my .gradle directory :( – matdev Jan 02 '18 at 15:12
  • try remove old cache and `clean` / `rebuild` .... the best way is to using task @matdev – Arash Hatami Jan 02 '18 at 15:14
  • 1
    I've tried using a task, but running it does not delete the classes.jar file contained in my .gradle/caches/transforms-1/files-1.1/ directory. Also, even with org.gradle.caching=false, the archive file keep on, reappearing in .gradle/caches – matdev Jan 09 '18 at 09:54
  • And what about this option ? `android.enableBuildCache=false` @matdev – Arash Hatami Jan 09 '18 at 17:20
  • I already set this flag to false, but the .gradle/caches keeps getting rebuilt – matdev Jan 10 '18 at 11:09
  • The task in your answer @ArashHatami , does not delete the aar file I'd like to delete. Do you know how to force delete aar files ? – matdev Jan 19 '18 at 11:01
  • 1
    this statement control delete process`if (cacheFile.name =~ "^$domain|^resolved-$domain")` @matdev – Arash Hatami Jan 19 '18 at 11:04
  • 1
    Many thanks ! I managed to clear the cached aar files by adding the line if (cacheFile.name =~ "^*.aar") delete cacheFile.path – matdev Jan 22 '18 at 09:48