How to configure gradle to work “offline” (using cached dependencies)

白昼怎懂夜的黑 提交于 2019-12-17 02:31:21

问题


I have a command line apk generator which compiles a lot of APKs using the same source code, so these apps have the same dependencies.

In the gradle documentation I can see this:

The Gradle project needs network connectivity to download dependencies.

I know that it is possible to configure gradle to work offline and not download the same dependencies that it has downloaded for other apks. How can this offline mode be activated?


回答1:


Gradle does a good job of avoiding re-downloading artifacts, but you can pass --offline to Gradle to prevent from accessing the network during builds.

e.g.

gradle --offline build

If it needs something from the network that it doesn't have, instead of attempting to fetch it, your build will fail.




回答2:


Android Studio

In Android Studio you can make gradle to build your apps fully offline by activating this option:

Settings -> Build, Execution, Deployment -> Build tools -> Gradle


Gradle CLI

In Gradle command line interface you can get this done by using --offline flag.

Specifies that the build should operate without accessing network resources.



来源:https://stackoverflow.com/questions/32171524/how-to-configure-gradle-to-work-offline-using-cached-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!