简体   繁体   English

Gradle无法从Android Studio中的jcenter()解析依赖项类路径

[英]Gradle cannot resolve dependencies classpath from jcenter() in Android studio

I`m using android studio 1.5.1 on ubuntu. 我在ubuntu上使用android studio 1.5.1。 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: 我想谷歌分析添加到我的Android app.So我跟着谷歌分析文档 ,但是当我改变mavenCentral()来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
    }

When I press "sync project with Gradle files`Button" , Android studio take about 15 minutes and finally says : 当我按下“使用Gradle文件`按钮同步项目”时,Android Studio大约需要15分钟,最后说:

Error:Connection timed out. 错误:连接超时。 If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle. 如果您使用HTTP代理,请在IDE或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()? 为什么我不能连接到jcenter()但可以连接到mavenCentral()?
  2. How can I sync gradle with my project to implement Google Analytic ? 如何与我的项目同步gradle以实施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'

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. 并且限制了下载Gradle依赖项。

A proxy or proxy server is basically another computer which serves as a hub through which internet requests are processed. 代理服务器或代理服务器基本上是另一台计算机,用作处理Internet请求的集线器。 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. 通过这些服务器之一进行连接,您的计算机会将您的请求发送到代理服务器,然后由代理服务器处理您的请求并返回您想要的内容。

Try this also First check your internet proxy settings copy the proxy settings like proxy host and port no. 也请尝试此操作首先检查您的Internet代理设置,复制代理设置,例如代理主机和端口号。 and go to your "gradle.properties" file in project and paste it like this 并转到项目中的“ gradle.properties”文件,然后将其粘贴为

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. 通常人们将系统道具粘贴为http,但忘记了https,因此请同时粘贴两者。

Sometimes firewalls from antivirus(i'm using AVG) might block the connection. 有时,防病毒防火墙(我正在使用AVG)可能会阻止连接。 Turn off the antivirus and refresh the project. 关闭防病毒并刷新项目。 Hope it might work, it worked in my case. 希望它可以工作,对我而言,它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM