How to copy Gradle caches to another offline machine?
Asked Answered
P

2

7

I've got two Ubuntu 16.04 machines. One is connected to the Internet, while the other one is fully offline. I'd like to build an Android project on the offline machine. On the online machine, it builds successfully. So, I've copied the entire .gradle to the offline machine and run build process with --offline flag. Surprisingly it fails. Lots of

No cached version of ....

I suspect it's because of the hash algorithm used to generate hash for each .jar, .pom, etc. I think hashes are different from one machine to another machine. Also note that my username and machine name are different in this two. It looks like hashes are related to the username. Am I right? Is there a clean solution to get the project built on the offline machine?

  • Gradle 4.0-bin
  • com.android.tools.build 2.3.0
Pentangular answered 23/7, 2017 at 12:20 Comment(1)
Solution: discuss.gradle.org/t/…Pentangular
C
0

There are a couple of directories that you can copy over to the offline machine:

$HOME/.gradle
$HOME/.android
$HOME/.m2

Along with the entire project that you have built. That will have a local .gradle directory as well.

Also make sure you have the android sdk m2 repo installed or make sure that you copy over the m2 repo for the support library found at "https://maven.google.com"

Chafin answered 24/7, 2017 at 2:35 Comment(9)
There's no .m2 directory, but there are only .gradle and .android. Copied both of them, still it keeps giving the same error.Pentangular
@HiI'mFrogatto are you copying over the entire project too?Chafin
Yes, entire project directory including that .gradle.Pentangular
I think those hash strings are the main culprit.Pentangular
@HiI'mFrogatto they could be and you are sure you do not have an $HOME/.m2 directory? Those hashes should be md5 so they should be good to transfer over.Chafin
I double checked now. There's no such directory indeed.Pentangular
Regarding hashes, md5 of what?Pentangular
Sorry it is the shasum of the file. For example this path: ~/.gradle/caches/modules-2/files-2.1/com.firebase/firebase-jobdispatcher-with-gcm-dep/0.5.2/63526b3c8b9638c21e9ced2f3b2963cde9d3c286 that hash is a shasum of the file firebase-jobdispatcher-with-gcm-dep-0.5.2.aar So that should be the same for what you have.Chafin
Let us continue this discussion in chat.Chafin
O
0

As per the official documentation, since at least version 6.1 of Gradle, it's possible to copy over the cache from the path $GRADLE_HOME/caches/modules-<version> to another machine for reuse. The only note is that the *.lock and gc.properties files from this directory should be skipped.

Overshoot answered 11/5, 2023 at 22:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.