情况:
并得到错误:
无法解决':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库”(上面的“两个”点),则没有此类错误。
对于这样一个简单的项目,默认情况下所有内容均不存在,因此不应出现此类错误。怎么了?
答案 0 :(得分:5)
尝试一下,替换:
implementation project(':testmodule')
收件人:
implementation project(path:':testmodule', configuration: 'default')
答案 1 :(得分:4)
转到
File -> Settings -> Build, Execution, Deployment -> Gradle menu.
您将看到“离线工作”选项。取消选中它。没关系
答案 2 :(得分:1)
您的插件似乎需要更改为apply plugin: 'com.android.library'
而不是'com.android.application'
有关更多信息,请参见此post 信息。希望有帮助。
答案 3 :(得分:0)
尝试在线模式进行gradle。希望对您有所帮助(我遇到了同样的问题,所以机会更多)。
答案 4 :(得分: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://i.stack.imgur.com/DY6sz.png