Nicolas Raoul
Nicolas Raoul

Reputation: 60213

I don't have a proxy, but Gradle says "Connect to 127.0.0.1:8888 [/127.0.0.1] failed", even after removing ~/.gradle

My gradle seems to insist on downloading packages from what looks like a proxy address. With this command I stop all Gradle daemons, remove any Gradle configuration, and build a random project from GitHub that has no proxy settings in its gradle.properties (I tried other projects, same result):

./gradlew  --stop ;\
pkill -f '.*GradleDaemon.*' ;\
rm -rf ~/.gradle ;\
env ;\
./gradlew build

The ./gradlew build part outputs this error:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'commons-app'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:4.0.0.
     Required by:
         project :
      > Could not resolve com.android.tools.build:gradle:4.0.0.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.0.0/gradle-4.0.0.pom'.
               > Connect to 127.0.0.1:8888 [/127.0.0.1] failed: Connection refused (Connection refused)

For reference, here is the output of the first commands, with a line break between each for clarity:

Stopping Daemon(s)
1 Daemon stopped

TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/jh/ffpydh_90rz7fhyq9ycryhnw00plfm/T/
TERM_PROGRAM_VERSION=433
OLDPWD=/Users/nicolasraoul/src
TERM_SESSION_ID=59D12079-D9B2-4C13-8366-219454D7760C
USER=nicolasraoul
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.OejMgJbaF5/Listeners
PATH=/Users/nicolasraoul/Library/Android/sdk/emulator:/Users/nicolasraoul/Library/Android/sdk/tools:/usr/local/git/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/Users/nicolasraoul/Library/Python/2.7/bin
PWD=/Users/nicolasraoul/src/commons-app2
ANDROID_SDK=/Users/nicolasraoul/Library/Android/sdk
LANG=en_US.UTF-8
XPC_FLAGS=0x0
HISTCONTROL=
XPC_SERVICE_NAME=0
HOME=/Users/nicolasraoul
SHLVL=1
LOGNAME=nicolasraoul
_=/usr/bin/env

Downloading https://services.gradle.org/distributions/gradle-6.2.2-all.zip
[...]

What could be the problem?

I have found several similar questions, but none of their answers apply because:

macOS Catalina 10.15.5

Upvotes: 15

Views: 11805

Answers (9)

Gem
Gem

Reputation: 61

After updating my AS to a new version (Android Studio Jellyfish | 2023.3.1, maybe the newer the better), and commented the http proxy settings in gradle.properties file as below, and rebuild the project succeeded! enter image description here

Upvotes: 0

fahrizal89
fahrizal89

Reputation: 845

I have some problem in my mac, after restart it solved my problem

Upvotes: 0

Jack.Li
Jack.Li

Reputation: 21

It was due to charles proxy issue in my situation, even though I quited the charles.

pkill -f '.*GradleDaemon.*'

can work.

Upvotes: 1

Nicolas Raoul
Nicolas Raoul

Reputation: 60213

To investigate I wrote this small Java program that output the system properties seen by Java:

public class Main {
        public static void main(String[] args) {
                System.out.println("Hello");
                System.getProperties().list(System.out);
        }
}

It revealed that Java sees a proxy even though env does not.

HTTP and HTTPS proxy had been enabled in the Mac System Properties somehow (I highly suspect the Charles program did it):

enter image description here

Unchecking them solved the problem, allowing Gradle to build successfully.

enter image description here

Upvotes: 7

Mohi Dev
Mohi Dev

Reputation: 3416

If you are a mac user goto below address and check the gradle.properties file for that proxy and comment it

$USER_HOME/.gradle/gradle.properties

> # systemProp.http.proxyHost=127.0.0.1
> # systemProp.http.proxyPort=10809
> # systemProp.https.proxyHost=127.0.0.1
> # systemProp.https.proxyPort=10809

If You are windows user goto

C:\Users\am823.gradle

And comment those lines.

Upvotes: 0

user21172102
user21172102

Reputation: 11

did you use charles to capture the http request?try to turn off the macos proxy in charles

Upvotes: 1

Werner Altewischer
Werner Altewischer

Reputation: 10474

If you had a proxy configured before but gradle still thinks that it is enabled, be sure to kill all gradle daemons:

pkill -f '.*GradleDaemon.*'

Upvotes: 40

Rui Cardoso
Rui Cardoso

Reputation: 747

After trying all the above options without sucess, I restarted my computer and now it works. I isn't a really technical solution but on another hand it is.

After more than 1 occurrence, I think it is related with Proxyman software, but just turning it off didn't work

Upvotes: 3

lance-java
lance-java

Reputation: 28099

It seems that you have some proxy settings which are redirecting your https traffic to 127.0.0.1:8888

Do you have the HTTPS_PROXY environment variable set?

Do you have https.proxyHost and https.proxyPort properties configured in $USER_HOME/.gradle/gradle.properties?

Upvotes: 11

Related Questions