Unable to resolve dependency for ':app@debug/c

2019-01-25 04:53发布

Newly installed Android studio 3.1.3 is giving strange dependencies error when making a new project and compiling for very first time.

A similar question that didn't help resolve the problem.

Event Logs:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details


Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details


Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details


Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details


Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0-alpha3.
Open File
Show Details


Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.2.
Open File
Show Details

ScreenShot:

TestProject

this problem happened to me several times and forcing https or http didn't resolve it either

9条回答
【Aperson】
2楼-- · 2019-01-25 04:57
  1. Try "File"->"Invalidate Caches / Restart ..."
  2. Try to clean up your .gradle and .idea directory under your project root directory.
  3. Try to add Google Maven repository and sync project

    buildscript {
        repositories {
            jcenter()
            google()
            maven {
               url "https://maven.google.com"
            }
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.3'
        }
    }
    
    allprojects {
        repositories {
            google()
            jcenter()
            maven {
               url "https://maven.google.com"
            }
        }
    }
    
  4. If you are using Android Gradle Plugin 3.1.3, you should be sure that your gradle wrapper version is 4.4. Under the root directory of your project, find gradle-wrapper.properties and modify it as below.

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
    
查看更多
做自己的国王
3楼-- · 2019-01-25 04:58

I'm just sharing this answer because I had similar problem.

In the end, error was caused because I inadvertently changed the fileTree. In my case, I fixed by changing:

// implementation or compile
implementation fileTree(include: ['*.jar'])

to

// implementation or compile
implementation fileTree(include: ['*.jar'], dir: 'libs')
查看更多
Explosion°爆炸
4楼-- · 2019-01-25 04:59

This can happen if you are using both

'com.android.support:appcompat-v7:28.0.0-alpha3'
'com.android.support:support-v4:28.0.0-alpha3'

Remove the line

implementation 'com.android.support:support-v4:28.0.0-alpha3' 

from your build.gradle file and try again.

查看更多
淡お忘
5楼-- · 2019-01-25 05:01

I think the problems comes from the following: The internet connection with u was unavailable so Android Studio asked you to enable the "offline work" and you just enabled it

To fix this:

  • File
  • Settings
  • Build, Execution, Deployment
  • Gradle
  • Uncheck offline work

why might unchecking the offline work solves the problem, because in the Gradle sometimes some dependencies need to update (the ones containing '+'), so internet connection is needed.

查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-25 05:02

In my case : When I setup AS, my windows was configured with proxy. Later, I disconnect proxy and disable proxy in AS settings, But, in file .gradle\gradle.properties - proxy - present

Just, in text editor clear proxy settings from this file

查看更多
虎瘦雄心在
7楼-- · 2019-01-25 05:09

I had your issue, i fixed it . this error comes when your target api level is not completely downloaded . you have two ways: go to your SDK menu and download all of the android 9 components or the better way is go to your build.gradle(Module app) and change it like this:But remember, before applying these changes, make sure you have fully downloaded api lvl 8

查看更多
登录 后发表回答