Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure gradle to work "offline" (using cached dependencies)

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?

like image 337
NullPointerException Avatar asked Aug 23 '15 21:08

NullPointerException


People also ask

How do I cache Gradle dependencies?

Generally, you can refresh dependencies in your cache with the command line option --refresh-dependencies. You can also delete the cached files under ~/. gradle/caches . With the next build Gradle would attempt to download them again.

Does Gradle require Internet connection?

Gradle needs an internet connection to download the dependencies that you specify. Once it downloads everything, it can put them in memory so that you can work offline. To do this, you need to go to Files->Settings (For Mac: Android Studio-> Settings...). You can now build your project without internet.


2 Answers

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.

like image 120
iagreen Avatar answered Sep 23 '22 12:09

iagreen


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

enter image description here


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.

like image 36
frogatto Avatar answered Sep 21 '22 12:09

frogatto