我如何告诉gradle从存储库中重新下载依赖项?


当前回答

这对我很管用。 通过取消文件>设置>Gradle>离线工作按钮,确保Gradle没有被设置为离线。

将其添加到构建的顶层。Gradle,很高兴有上面的依赖

configurations.all {
    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}

我确保我的依赖是这样写的:

implementation('com.github.juanmendez:ThatDependency:ThatBranch-SNAPSHOT') {
    changing = true
}

之后,我打开Android Studio中的Gradle面板,点击蓝色圆圈箭头按钮。我总是能看到我的更新得到一个新的新鲜副本。

其他回答

对于大多数情况,只需简单地重新构建项目就可以了。有时你必须运行。/gradlew build——refresh-dependencies,就像前面提到的那样(需要很长时间,取决于你有多少依赖)。无论如何,有时这些都不会工作:依赖项不会被更新。然后,你可以这样做:

从gradle文件中删除依赖项 运行/调试你的项目并等待它失败(以NonExistingClass的原因) 点击“构建项目”并等待它成功完成 再次运行/调试

这很荒谬,看起来很疯狂,但我实际上每天都在使用这个过程,只是因为我需要的依赖关系可以更新几十次,而任何适当的解决方案都不会有任何效果。

您需要重新下载它,因此您可以手动下载并替换损坏的文件,并再次同步您的项目。去这个位置 C: \用户【用户名】.gradle \包装\ dist gk2rcmfc6p2dg9u9ohc3hw9 55 \ gradle3.3-all \ \ gradle all.zip——3.3 在此删除gradle3.3allzip,并重新从该站点下载 https://services.gradle.org/distributions/ 找到相同的文件,下载并粘贴到该位置 然后同步你的项目。 希望它也适用于你。

有两种方法:

使用命令行选项刷新依赖项现金。 您可以删除本地缓存,其中artefast是由Gradle和触发构建缓存

使用——refresh-dependencies选项:

./gradlew build --refresh-dependencies

简单解释——refresh-dependencies选项告诉Gradle忽略已解析模块和工件的所有缓存条目。

长explanantion

WIth –refresh-dependencies’ Gradle will always hit the remote server to check for updated artifacts: however, Gradle will avoid downloading a file where the same file already exists in the cache. First Gradle will make a HEAD request and check if the server reports the file as unchanged since last time (if the ‘content-length’ and ‘last-modified’ are unchanged). In this case you’ll get the message: "Cached resource is up-to-date (lastModified: {})." Next Gradle will determine the remote checksum if possible (either from the HEAD request or by downloading a ‘.sha1’ file).. If this checksum matches another file already downloaded (from any repository), then Gradle will simply copy the file in the cache, rather than re-downloading. In this case you’ll get the message: "“Found locally available resource with matching checksum: [{}, {}]”.

使用删除: 当你删除缓存

rm -rf $HOME/.gradle/caches/

你只需要清理所有缓存的jar和sha1和,Gradle在你的机器上没有工件的情况下,必须下载所有东西。是的,第一次它将100%工作,但是当另一个快照被释放并且它是依赖树的一部分时,您将再次面临刷新或清除缓存的选择。

Android Studio 3.4.1

简单地打开gradle选项卡(可以位于右侧),右键单击列表中的父项(应该称为“Android”),然后选择“刷新依赖项”。

这将解决您的问题。

你可以这样做

https://marschall.github.io/2017/04/17/disabling-gradle-cache.html

引用自禁用Gradle构建缓存

当你经常使用Gradle构建>个大型项目时,Gradle构建缓存可能是一个很棒的东西。然而,如果只是偶尔构建开源>项目,它很快就会变得很大。 要禁用Gradle构建缓存,请在~/.gradle/ Gradle .properties中添加以下代码行 org.gradle.caching = false 可以清除现有缓存 rm -rf $HOME/.gradle/caches/ rm -rf $HOME/.gradle/wrapper/