gradle - 无法解决 ':app@debugUnitTest/compileClasspath'、:app@debugAndroidTest/compileClasspath 的依赖关系

标签 gradle dependencies

情况:

  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”(上面点“二”),则不存在此类错误。

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

最佳答案

试试这个,替换:

implementation project(':testmodule')

收件人:

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

关于gradle - 无法解决 ':app@debugUnitTest/compileClasspath'、:app@debugAndroidTest/compileClasspath 的依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51031514/

相关文章:

java - 如何在 Gradle 模块之间共享单个包或类?

java - 在 Mac 上使用更新的类覆盖 Java 系统库

c++ - Maven NAR 插件 : DLL dependency not found on path

javascript - 无法安装 node-sass 依赖项

gradle - 使用Gradle完成多级目录项目

java - 将 commons-net jar 添加到 build.gradle 文件

spring - 为什么 Maven 会下载不同版本的 Spring Artifact ?

linux - 如何摆脱 'GLIBCXX_3.4.9 not found error' ?

groovy - 如何为现有的 IDEA 项目创建 Gradle 构建?

gradle - 如何将子模块转换为 jar 并将其用作依赖项而不是项目本身