Gradle cannot resolve dependencies classpath from

2019-09-10 01:18发布

问题:

I`m using android studio 1.5.1 on ubuntu. I want to add google analytic to my android app.So I followed google analytic document but when I change mavenCentral() to jcenter() , Android studio cannot resolve this classpath:

dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-beta6'
        classpath 'com.google.gms:google-services:2.0.0-alpha6'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

When I press "sync project with Gradle files`Button" , Android studio take about 15 minutes and finally says :

Error:Connection timed out. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.

However I used and did not used proxy , And result was same.

  1. Why I cannot connect to jcenter() but I can connect to mavenCentral()?
  2. How can I sync gradle with my project to implement Google Analytic ?

Thanks.

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-beta6'
        classpath 'com.google.gms:google-services:2.0.0-alpha6'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

=============================

compile 'com.google.android.gms:play-services:8.4.0'

回答1:

I think your network is restricted to access some sites or download from those sites.

If you are working from your office then it may have a proxy server. and it is restricting from downloading Gradle dependencies.

A proxy or proxy server is basically another computer which serves as a hub through which internet requests are processed. By connecting through one of these servers, your computer sends your requests to the proxy server which then processes your request and returns what you were wanting.



回答2:

Try this also First check your internet proxy settings copy the proxy settings like proxy host and port no. and go to your "gradle.properties" file in project and paste it like this

systemProp.http.proxyHost="copied proxy host"
systemProp.http.proxyPort="copied proxy port"

systemProp.https.proxyHost="copied proxy host"
systemProp.https.proxyPort="copied proxy port"

Generally people paste the system prop for http but forget for https so please paste both.



回答3:

Sometimes firewalls from antivirus(i'm using AVG) might block the connection. Turn off the antivirus and refresh the project. Hope it might work, it worked in my case.