Unable to resolve dependency for ':app@debugUnitTest/compileClasspath', :app@debugAndroidTest/compileClasspath

我是研究僧i 提交于 2019-12-13 16:50:09

问题


Situation:

  1. Create the simplest project
  2. Add to the project module as File -> New -> New module "Phone & Tablet Module"
  3. Add the dependency on the module

And get errors:

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

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :testmodule.

Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :testmodule.

Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :testmodule.

Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :testmodule.

Below are the project files:

Project:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Module: app

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.pawga.test00"
        minSdkVersion 14
        targetSdkVersion 28
        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:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation project(path: ':testmodule')
}

Module: testmodule

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28



    defaultConfig {
        applicationId "com.pawga.testmodule"
        minSdkVersion 14
        targetSdkVersion 28
        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:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

gradle-wrapper.properties

#Mon Jun 25 22:51:52 2018
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

settings.gradle

include ':app', ':testmodule'

Note: If the module type is "Android Library" (Point "two" above), then there are no such errors.

For such a simple project, where everything is by default, there should not be such errors. What's wrong?


回答1:


Try this, replace:

implementation project(':testmodule')

To:

implementation project(path:':testmodule', configuration: 'default')



回答2:


Go to

File -> Settings -> Build, Execution, Deployment -> Gradle menu. 

You will see "Offline work" options. Uncheck it. And it's ok.




回答3:


It looks like your plugin needs to be changed to apply plugin: 'com.android.library' instead of 'com.android.application'

See this post for more information. Hope that helps.




回答4:


Try online mode for gradle. Hope it helps(I had the same problem, so more chances).




回答5:


##REMOVE THE FOLLOWING FROM THE BUILD GRADLE##
>>implementation 'com.android.support:appcompat-v7:28.+'
>>implementation 'com.android.support.constraint:constraint-layout:1.0.2'
>>androidTestImplementation 'com.android.support.test:runner:1.0.1'
>>androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
>>SEE ATTACHED PICTURE
>>[STUDIO ERRORS][1]
  >>[1]: https://i.stack.imgur.com/DY6sz.png


来源:https://stackoverflow.com/questions/51031514/unable-to-resolve-dependency-for-appdebugunittest-compileclasspath-appdeb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!