Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve

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

like image 465
Zulqurnain Jutt Avatar asked Jul 06 '18 22:07

Zulqurnain Jutt


4 Answers

You might be importing Application instead of Module. Well you can change it in module's gradle also.

Change

apply plugin: 'com.android.application'

to

apply plugin: 'com.android.library'

You also need to remove applicationId from the gradle.

like image 127
Shahbaz Hashmi Avatar answered Oct 17 '22 03:10

Shahbaz Hashmi


I just figured out how to remove this gradle error, follow the following steps.

  1. Go to "File".
  2. Click on Invalidate Cache/ Restart.
  3. Again click on Invalidate Cache / Restart(On dialoge window).

Let the gradle build without any interruption.

Thank You! Regards, hope this will help.

like image 25
Prateek Bhandari Avatar answered Oct 17 '22 03:10

Prateek Bhandari


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.

like image 12
Mohammad Elsayed Avatar answered Oct 17 '22 05:10

Mohammad Elsayed


  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
    
like image 11
shizhen Avatar answered Oct 17 '22 05:10

shizhen