无法解决依赖项':app@debugUnitTest/compileClasspath',':app@debugAndroidTest/compileClasspath'。

3

情况:

  1. 创建最简单的项目
  2. "Phone & Tablet Module"作为文件 -> 新建 ->新模块添加到项目中
  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库”(参见上面的“第二点”),则不会出现此类错误。
对于这样一个简单的项目,一切都是默认值,不应该出现这样的错误。出了什么问题?
5个回答

5

请尝试以下操作,将其替换为:

implementation project(':testmodule')

To:

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

1
你能指出你是从哪里找到这个答案的吗?有没有相关文档? - Piotr Z

3

请前往

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

您会看到“离线工作”选项。取消勾选即可。这样就可以了。

1

看起来你的插件需要更改为apply plugin: 'com.android.library'而不是'com.android.application'

查看此文章获取更多信息。希望对你有所帮助。


Studio没有禁止在此配置中添加此插件。这让我感到尴尬。而且在这个模块中需要像activity这样的元素。正如我之前所指出的,"Android Library"模块(插件:'com.android.library')没有问题。我有一个解决方案可以使用"Android Library"模块。但对于我的情况来说,它不如"Phone&Tablet Module"模块美观。 - Pawga

0
##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://istack.dev59.com/DY6sz.webp

这是对我有效的方法。 我正在使用Android Studio 3.1.3。 - Polo001

0

尝试使用gradle的在线模式。希望它有所帮助(我也遇到了同样的问题,所以更有机会解决)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接