【问题标题】:Unable to resolve dependency for ':app@debugUnitTest/compileClasspath', :app@debugAndroidTest/compileClasspath无法解析 ':app@debugUnitTest/compileClasspath'、:app@debugAndroidTest/compileClasspath 的依赖关系
【发布时间】:2018-12-04 12:05:29
【问题描述】:

情况:

  1. 创建最简单的项目
  2. 作为文件添加到项目模块 -> 新建 -> 新模块“手机和平板电脑模块”
  3. 添加对模块的依赖

并得到错误:

无法解析 ':app@debug/compileClasspath' 的依赖关系:无法解析项目 :testmodule。

无法解析 ':app@debugAndroidTest/compileClasspath' 的依赖关系:无法解析项目 :testmodule。

无法解析 ':app@debugUnitTest/compileClasspath' 的依赖关系:无法解析项目 :testmodule。

无法解析 ':app@release/compileClasspath' 的依赖关系:无法解析项目 :testmodule。

无法解析 ':app@releaseUnitTest/compileClasspath' 的依赖关系:无法解析项目 :testmodule。

以下是项目文件:

项目:

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
}

模块:应用程序

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')
}

模块:测试模块

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'

注意: 如果模块类型是“Android Library”(上面点“二”),那么就没有这样的错误。

对于这样一个简单的项目,一切都是默认的,不应该出现这样的错误。怎么了?

【问题讨论】:

    标签: gradle dependencies


    【解决方案1】:

    试试这个,替换:

    implementation project(':testmodule')
    

    收件人:

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

    【讨论】:

    • 你能指出你是从哪里得出的吗?可能有任何文件吗?
    【解决方案2】:

    前往

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

    您将看到“离线工作”选项。取消选中它。没关系。

    【讨论】:

      【解决方案3】:

      您的插件似乎需要更改为 apply plugin: 'com.android.library' 而不是 'com.android.application'

      查看post 了解更多信息 信息。希望对您有所帮助。

      【讨论】:

      • Studio 并未禁止在此配置中添加此类插件。这让我很尴尬。而在这个模块中需要activity等元素。正如我之前提到的,“Android 库”模块(插件:'com.android.library')没有问题我有一个使用“Android 库”模块的解决方法选项。但就我的情况而言,它不如“手机和平板模块”模块漂亮。
      【解决方案4】:

      尝试 gradle 的在线模式。希望对您有所帮助(我遇到了同样的问题,所以机会更多)。

      【讨论】:

        【解决方案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
        

        【讨论】:

        • 这对我有用。我正在使用 Android Studio 3.1.3
        猜你喜欢
        • 2019-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-24
        • 1970-01-01
        • 2018-07-23
        • 2018-12-15
        • 1970-01-01
        相关资源
        最近更新 更多