0

Well, I met a problem about gradle sync today.
The problem is like this:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:design:27.1.0.

But I actually add the dependence in app/build.gradle dependencies like this

dependencies {
  ...
  implementation 'com.android.support:appcompat-v7:27.1.0'
  ...
  implementation 'com.android.support:design:27.1.0'
  ...
} 

I didn't turn the gradle offline mode on. And it is connected to the Internet. But it seems didn't auto download the dependence. Also other dependencies like this

implementation 'de.hdodenhof:circleimageview:2.2.0'

I can't solve it. Each answer is helpful. The detailed gradle properties is like this.

{
compileSdkVersion 27
defaultConfig {
    applicationId "com.example.lqs2.materialtest"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:recyclerview-v7:24.2.1'
implementation 'com.android.support:cardview-v7:24.2.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

}

treeliked
  • 383
  • 1
  • 4
  • 15

2 Answers2

0

Are your repositories correct? Please verify if:

repositories {
    google()
    jcenter()
}

In your project's Build.Gradle (Note: the project's Build.Gradle, not the module's).

Luís Henriques
  • 604
  • 1
  • 10
  • 30
  • Yes, it has correct repositories. But the problem always occurred. Any dependency can't be resolved. I have ever turned on the Http proxy. But I have turned it off. – treeliked Apr 06 '18 at 03:26
  • Ok. Why do you have "implementation fileTree(dir: 'libs', include: ['*.jar'])"? Are you trying to use libraries as files in your /libs directory? – Luís Henriques Apr 06 '18 at 09:17
  • It was auto generated. I tried to rebuild the project . I found that ---------------Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:80 [/127.0.0.1] failed: Connection refused (Connection refused). – treeliked Apr 06 '18 at 11:15
  • My guess was that there were conflicts between the *.jar files you had in your /libs folder and the ones you are importing from the repositories. You can't have the same libraries on both. Either use one approach or the other. But if it's not that, I am out of ideas. Maybe if you provide more info. Can you post the full stack trace? – Luís Henriques Apr 06 '18 at 13:20
  • I have solved the problem. I reinstalled the gradle and it works well now. Thank you very much. – treeliked Apr 08 '18 at 08:40
  • No problem. I'm glad you found the solution. – Luís Henriques Apr 09 '18 at 09:20
0

The order of the repositories appears to be important. Try placing "google" before "jcenter"

AndroidGuy
  • 3,371
  • 1
  • 19
  • 21