无法解析':app @ debugUnitTest / compileClasspath',:app @ debugAndroidTest / compileClasspath的依赖关系

Paw*_*wga 2 dependencies gradle

情况:

  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
}
Run Code Online (Sandbox Code Playgroud)

模块:应用

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')
}
Run Code Online (Sandbox Code Playgroud)

模块: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'
}
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

settings.gradle

include ':app', ':testmodule'
Run Code Online (Sandbox Code Playgroud)

注意:如果模块类型为“ Android库”(上面的“两个”点),则不会出现此类错误。

对于这样一个简单的项目,默认情况下所有内容都是默认的,因此不应有此类错误。怎么了?

小智 5

试试这个,替换:

implementation project(':testmodule')
Run Code Online (Sandbox Code Playgroud)

至:

implementation project(path:':testmodule', configuration: 'default')
Run Code Online (Sandbox Code Playgroud)