问题
Why my program hang on resolving dependency for appDebug in andorid studio? I can't resolve any library.
This is my root gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
and this is my app gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.alimohammadi.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
And I can't resolve junit. And I can't access to https://jcenter.bintray.com/ with my browser (it gave me connection time out while other site return true response).
回答1:
After one day time wasting i found that it's gift for Iranian developer :D
Finally i switch back to mavenCentral().by changing to mavenCentral() in my root gradle . and problem solved.
My root build.gradle file turn to below code:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Some library don't exist in mevenCentral so we have to add proxy to our gradle.properties file like below to access jcenter :D
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=user
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=localhost
systemProp.http.auth.ntlm.domain=domain
Or for https
systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=user
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=localhost
systemProp.https.auth.ntlm.domain=domain
回答2:
After long hours of investigation solution came to me unexpectedly. - Try building your gradle with different network or mobile hotspot. Works for me.
回答3:
I faced the exact same issue when I tried to include in my build.gradle the following dependency classpath 'com.google.gms:google-services:3.0.0' in order to have
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.google.gms:google-services:3.0.0'
}
}
I got Timeout on gradle resolution path. So far (when only the classpath to the gradle:2.3.0
was present), I in fact was working with my cache, so I didn't notice that my proxy was not correctly set.
So I tried to select manual proxy: Settings->Apperance&Behaviour-> System Settings ->Http Proxy
with Hostname and port number.
So the associated gradle.properties
was:
systemProp.http.proxyHost=proxy<blabla>.com
systemProp.http.proxyPort=123 (123 is just an example)
but I still had the problem. Caramba!! So I noticed that the files I needed are located here:
https://jcenter.bintray.com/com/android/tools/build/gradle/2.3.0/
but Android studio does not provide a UI to set the proxy on HTTPS so I manually edit the gradle.properties
to duplicate the line for https
systemProp.http.proxyHost=proxy<blabla>.com
systemProp.http.proxyPort=123 (123 is just an example)
systemProp.https.proxyHost=proxy<blabla>.com
systemProp.https.proxyPort=123
And.... it works for me. Don't need to change jcenter to mavenCentral.
来源:https://stackoverflow.com/questions/35243515/cant-resolve-dependency-in-android-studio-with-jcenter