2

Whenever I try to open a project or Create a new project in Android Studio, I encounter a Gradle Project Sync error. Android Studio is displaying an error which states "Connection to The Internet Denied". I searched the possible solutions on Stack Overflow and also the Android Developers Website, but was not successful.

I tried all the possible solutions given in the following posts and documentation, but none of them worked for me.

  1. Create new project on Android, Error: Studio Unknown host 'services.gradle.org'
  2. Android Studio Connection Refused
  3. https://developer.android.com/studio/troubleshoot.html
  4. Android Studio internet connection

Here are the build.gradle and gradle.properties files:

build.gradle -

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

gradle.properties -

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.

org.gradle.jvmargs=-Djava.net.preferIPv4Stack=true
systemProp.https.proxyHost=localhost
systemProp.https.proxyPort=8080

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

When I use localhost as my ProxyHost, it throws an error saying Connection Refused: connect

Could somebody guide me in fixing this error? Thanks in Advance.

Suprad Parashar
  • 39
  • 2
  • 11

2 Answers2

0

This problem caused the previously installed gradle wrapper doesn't inherent the network access permission. You can fix this by letting Android Studio manage the gradle wrapper; Go to File/Settings/Build Execution Deployment/Gradle and check Use local gradle distribution.

After that, in Gradle Home put the location to the gradle directory - at this moment gradle 4.4 is latest; i.e. 'C:\Program Files\Android\Android Studio\gradle\gradle-4.4'

And fix, or comment out those proxy setting in 'gradle.properties':

#systemProp.http.proxyHost=127.0.0.1
#systemProp.https.proxyHost=127.0.0.1

#systemProp.http.proxyPort=1080
#systemProp.https.proxyPort=1080
-1

I just ran into the same problem this morning, and I fixed it by disabling all firewall rules in Windows Defender Firewall using Windows 10, retry syncing and it worked just fine !