What is gradle sync in Android Studio?
Asked Answered
A

3

31

What is it? And what does it do? I'm working on an enterprise that has a proxy, and it fails trying to connect to somewhere. Why does it needs internet connection? What ports does it use?

EDIT: The answer of the user Caleb was perfect. I would like to add that the proxy should be configured too in the gradle.properties. Something like this:

systemProp.http.proxyHost=*proxyAddress*

systemProp.http.proxyPort=*portNumber*

systemProp.https.proxyHost=*proxyAddress*

systemProp.https.proxyPort=*portNumber*

Ambition answered 26/4, 2017 at 14:13 Comment(2)
Look at this link... it may help linkSphincter
Thanks for the link, but it does not say why do we need that internet connection :(.Ambition
F
35

What is it? And what does it do?

Gradle sync is a gradle task that looks through all of your dependencies listed in your build.gradle files and tries to download the specified version.

dependencies {
     compile '...your dependency...'
}

Why does it needs internet connection? What ports does it use?

It requires an internet connection because it is usually downloading these dependencies from a remote location. You can define what ports it uses by changing your gradle.properties. (see below)

I'm working on an enterprise that has a proxy, and it fails trying to connect to somewhere.

Your work proxy may be blocking this and you'll need to add your proxy configuration to solve your issues.

Go into:

File-->Settings--> Android Studio Preferences --> Appearance & Behavior / System Settings/ HTTP Proxy

and update your proxy configuration url to your work proxy. (automatic or manual depending on your setup).

NOTE: If you are using the command line to run your gradle build, you will probably need to update the proxy settings via your gradle.properties file.

Global Properties File Location : ~/.gradle/gradle.properties (or use your local project file if you have one)

Add proxy settings to this file:

HTTPS

systemProp.https.proxyHost=<proxy host>
systemProp.https.proxyPort=<your proxy port>
systemProp.https.nonProxyHosts=<your non-proxy host>
systemProp.https.proxyPassword=<your pw>

HTTP

systemProp.http.proxyHost=<proxy host>
systemProp.http.proxyPort=<your proxy port>
systemProp.http.nonProxyHosts=<your non-proxy host>
systemProp.http.proxyPassword=<your pw>

If you absolutely cannot get an internet connection via gradle you'll need to download the dependencies another way and reference them locally on your computer or local network.

(See this guide for using local jars)

Froissart answered 19/5, 2017 at 18:53 Comment(3)
should i put it in gradle properties project or module for the proxy configuration?Moonrise
I would put it at the project level or the global level. (~/.gradle/gradle.properties for mac)Froissart
I want to see the source code of it, but I don't know where it is.Besotted
D
8

What is it?

I believe it's an IntelliJ/Android Studio term for these Gradle tasks:

  1. dependencies
  2. build

Gradle itself doesn't have "sync" task.

I use the term "believe" since there's no explanation from Gradle/IntelliJ/Android Studio official documentation 😂

And what does it do? Sync is a phase where the IDE preparing everything, including downloading your dependencies.

When the sync is finished, the user can start coding.

When the sync fails, the IDE is not working properly. The user need to spend time to fix the configuration first.

After Gradle finished syncing, the IDE start another task, like indexing.

Gradle: Build...
Gradle: Configure projects...
Indexing...

I'm working on an enterprise that has a proxy, and it fails trying to connect to somewhere. Why does it needs internet connection? What ports does it use?

Answered above.

Bonus: How to speed up sync

Before opening the project using Android Studio/IntelliJ, open the project using terminal and run the gradle tasks.

cd myproject
./gradlew app:dependencies module:dependencies
./gradlew build

After that, open the project. The sync should be much faster now (since you've downloaded the dependencies in terminal).

Discrete answered 18/6, 2020 at 2:36 Comment(1)
You can sync without building. A gradle build involves compiling, assembling and verifying your code. A gradle sync just builds buildSrc, downloads dependencies and aligns the IDE with the settings in the build scriptOppression
U
3

It needs internet connection to download dependencies

Ungrudging answered 26/4, 2017 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.