无法解析“:app@debugUnitTest/compileClasspath”、:app@debugAndroidTest/compileClasspath 的依赖关系

2024-01-13

情况:

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

并得到错误:

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

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

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

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

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

以下是项目文件:

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
}

模块:应用程序

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

设置.gradle

include ':app', ':testmodule'

笔记: 如果模块类型是“Android Library”(上面的“二”点),则不会出现此类错误。

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


试试这个,替换:

implementation project(':testmodule')

To:

implementation project(path:':testmodule', configuration: 'default')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法解析“:app@debugUnitTest/compileClasspath”、:app@debugAndroidTest/compileClasspath 的依赖关系 的相关文章

随机推荐