问题
Situation:
- Create the simplest project
- Add to the project module as File -> New -> New module "Phone & Tablet Module"
- Add the dependency on the module
And get errors:
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :testmodule.
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :testmodule.
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :testmodule.
Unable to resolve dependency for ':app@release/compileClasspath': Could not resolve project :testmodule.
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project :testmodule.
Below are the project files:
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
}
Module: app
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')
}
Module: 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'
Note: If the module type is "Android Library" (Point "two" above), then there are no such errors.
For such a simple project, where everything is by default, there should not be such errors. What's wrong?
回答1:
Try this, replace:
implementation project(':testmodule')
To:
implementation project(path:':testmodule', configuration: 'default')
回答2:
Go to
File -> Settings -> Build, Execution, Deployment -> Gradle menu.
You will see "Offline work" options. Uncheck it. And it's ok.
回答3:
It looks like your plugin needs to be changed to apply plugin: 'com.android.library'
instead of 'com.android.application'
See this post for more information. Hope that helps.
回答4:
Try online mode for gradle. Hope it helps(I had the same problem, so more chances).
回答5:
##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
来源:https://stackoverflow.com/questions/51031514/unable-to-resolve-dependency-for-appdebugunittest-compileclasspath-appdeb