AGP 4.2.2
gradle-6.7.1
arcticfox 2020.3.1
Everytime I build my android project I see this maven-metadata.xml and it just seems to slow the build and it just seems to hang there. Which can take 10 minutes for each build.
Is there a way to avoid this?
Gradle: Download maven-metadata.xml...
When I run one the command line I see this:
This is my gradle.properties
org.gradle.jvmargs=-Xmx8g -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=256m -XX:+UseCompressedOops -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
org.gradle.configureondemand=true
kotlin.coroutines=enable
kotlin.code.style=official
kapt.use.worker.api=true
kapt.incremental.apt=true
android.enableD8.desugaring=true
android.useAndroidX=true
android.enableJetifier=true
I am using some maven repositories as specified here in build.gradle(app):
maven { url "https://www.jitpack.io" }
maven { url 'http://......./repo/maven2' }
maven { url "https://....../repositories/snapshots" }
maven { url 'https://....../maven/release' }
maven { url "http://......./bintray.com/maven" }
maven { url "https://....../objectbox/objectbox" }
5
Answers
The cause of slow downloads for
maven-metadata.xml
files is that one of your proxy repositories has a very slow remote.This problem will be compounded if either of the
"metadata max age"
and"not found cache ttl"
settings is set too low. Thus it will check the circle too fast and download it everytime from scratch. Turn it up to 12 hours. Default should be 30min (1800sec) what is a too short period of time.For setting the
max age
you can simple follow along this site.Another good article to manage
Http Cache Headers
.The question is kind of insufficient to tell, because no
build.gradle
had been provided. But I’d assume, that the reason is any-SNAPSHOT
dependency, which is not being cached. Building against a local copy of that dependency should result in not downloading themaven-metadata.xml
over and over again; or usemavenLocal()
. Building against a stable version should also result in caching.Gradle usually needs to download a
maven-metadata.xml
file, ifFor (1) you should look for versions like
1.2.3-SNAPSHOT
or1.2.+
on your declared dependencies (or at./gradlew dependencies
for simplicity). If you have any such versions, do you really need them? Using fixed versions like1.2.3
should be faster.For (2), have you maybe changed the default TTL threshold or do you maybe always build with
--refresh-dependencies
? If not, then the slowness should at least not occur more often than once a day.If the above doesn’t help, then maybe try running your build with
--info
or--info --refresh-dependencies
and carefully watch the log output. That should show which dependency and/or which repository is the culprit (i.e., the one on which the logging is stuck for the longest time). If you find such a culprit, then you could look into things likemaven-metadata.xml
file (if you control the repository).If all this still doesn’t turn up actionable items, then maybe it could be worth looking for bigger
maven-metadata.xml
files in your Gradle dependency cache. Maybe the repeated download of such big files is the issue and one of the approaches from the previous list could help. Here’s an idea for how to find the ten biggestmaven-metadata.xml
files (with a Unix shell command):Chriki answer directed me in the right direction to find a simple solution. After you have downloaded all dependencies (in my case, I am using -SNAPSHOT library, which wants to be updated on every run), you can set Gradle in offline mode. This will prevent Gradle to download new metadata, etc.
In Android Studio you have a dedicated button to toggle online mode (see image
Android studio settings).
Other answers give very good context on why this happens. Especially when using
-SNAPSHOT
dependencies, if you have no other way, I have a trick for you that might help a lot.It is to use offline mode 🎉
When running via CLI, do
When running via IDE, enable offline mode.