3

Situation:

  1. Create the simplest project
  2. Add to the project module as File -> New -> New module "Phone & Tablet Module"
  3. 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?

Pawga
  • 31
  • 2
  • 3

5 Answers5

5

Try this, replace:

implementation project(':testmodule')

To:

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

Go to

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

You will see "Offline work" options. Uncheck it. And it's ok.

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
1

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.

coderpc
  • 4,119
  • 6
  • 51
  • 93
  • Studio did not forbid to add such a plugin in this configuration. This embarrassed me. And in this module need elements such as activity. As I noted before, there are no problems with the "Android Library" module (plugin: 'com.android.library') I have a workaround option for working with "Android Library" module. But it is not as beautiful as the module "Phone & Tablet Module" for my case. – Pawga Jun 26 '18 at 10:36
0

Try online mode for gradle. Hope it helps(I had the same problem, so more chances).

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
Polo001
  • 1
  • 1