27

I'm making my first android wear app, but I can't get Android Studio working. First I got the error

 "Project with path ':wear' could not be found in project ':mobile'. 

This was resolved by adding "include ':wear" in settings.gradle.
But then a new error occurs:

"Error:Module version Test2:mobile:unspecified, configuration 'wearApp' declares a dependency on configuration 'default' which is not declared in the module descriptor for Test2:wear:unspecified" .

What do I have to do to resolve that error?

Just in case it's needed: here's build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.verbraeken.joost.test2"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    wearApp project(':wear')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.android.support:design:23.1.1'
}

settings.gradle:

include ':mobile'
include ':wear'
Angela
  • 316
  • 2
  • 10
Joost Verbraeken
  • 883
  • 2
  • 15
  • 30
  • Please paste your build.gradle of wear here. – starkshang Nov 15 '15 at 10:29
  • Android Studio didn't make a build.gradle for wear. It only made settings.gradle, the top level build.gradle and mobile build.gradle – Joost Verbraeken Nov 15 '15 at 10:53
  • Hi, I am getting Issue like this. "Error:A problem occurred configuring project ':app'. > Could not resolve all dependencies for configuration ':app:_debugApk'. > Project :app declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :linkedin-sdk." – Naveen Oct 03 '17 at 13:16

5 Answers5

54

In Android Studio 3.0 the documentation for Migrate to the New Plugin says:

dependencies {
    // This is the old method and no longer works for local
    // library modules:
    // debugCompile project(path: ':foo', configuration: 'debug')
    // releaseCompile project(path: ':foo', configuration: 'release')

    // Instead, simply use the following to take advantage of
    // variant-aware dependency resolution. You can learn more about
    // the 'implementation' configuration in the section about
    // new dependency configurations.
    implementation project(':foo')

    // You can, however, keep using variant-specific configurations when
    // targeting external dependencies. The following line adds 'app-magic'
    // as a dependency to only the 'debug' version of your module.

    debugImplementation 'com.example.android:app-magic:12.3'
}

So change this

    debugCompile project(path: ':foo', configuration: 'debug')
    releaseCompile project(path: ':foo', configuration: 'release')

to this

    implementation project(':foo')
Jonas Borggren
  • 2,591
  • 1
  • 22
  • 40
  • 3
    I am getting following error Error:(151, 1) A problem occurred evaluating project ':app'. > Could not find method implementation() for arguments [project ':xyz'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. – Manish Jul 01 '17 at 13:29
  • @Manish you need Android Studio 3.0.0 minimum to use the implementation() method. It is not available in AS 2.3.3/Production yet. – Aceofspadez44 Jul 28 '17 at 18:45
  • I'm in android 3, same issue. Error:(225, 0) Could not find method implementation() for arguments [project ':commons'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. – StarWind0 Sep 25 '17 at 16:52
  • @UmarulFarukh I'm having the same issue trying to bundle the watch module to the phone module in Android Studio 3.0. Did you solve that? – steliosf Nov 07 '17 at 00:36
  • It solves SOME issues. I still get this for example: Unable to resolve dependency for ':@releaseTest/compileClasspath': – Radu Nov 13 '17 at 19:24
  • I have this problem too, but it's worth noting that the "Migration to the New Plugin" document quoted above now states "This is the old method and no longer works for local". I'm still looking for a solution. – Slartibartfast May 22 '18 at 08:28
6

Error:Module version Test2:mobile:unspecified, configuration 'wearApp' declares a dependency on configuration 'default'

It means that a module (wearApp in your case) doesn't have a build.gradle file or a right configuration inside the build.gradle file.

Since you define a module in settings.gradle you have to provide a build.gradle for each module.

In your case:

root
|-- mobile
|----build.gradle
|-- wear
|----build.gradle
|--build.gradle
|--settings.gradle
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • What if the module is external library which has java files in it?I followed the same steps but still getting the same error. Error:Project :app declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :recognito. Link to library i want to include https://github.com/amaurycrickx/recognito i have made changes to settings.gradle and app build.gradle – ugola Jun 07 '17 at 06:49
  • in my case, I had credential issues accessing a git submodule, thus the content of the module was empty. Thanks! – Maragues Aug 03 '17 at 08:40
3

If you're not using Android Studio 3.0, this worked for me, in your build.gradle lib:

publishNonDefault true

like this

android {
    compileSdkVersion maxApiLevel.toInteger()
    buildToolsVersion androidBuildToolsVersion
    publishNonDefault true

    [...]
}

And in your include build.gradle:

dependencies {
    debugCompile project(path: ':foo', configuration: 'debug')
    releaseCompile project(path: ':foo', configuration: 'release')
}
Blaaz
  • 91
  • 1
  • 4
2

I am using ionic cordova for build my app, in my case the file build.grade was updated each time, I have to change the file "app_path>node_modules\cordova-android\bin\templates\cordova\lib\builders\GradleBuilder.js" from:

    console.log('Subproject Path: ' + p);
    var libName=p.replace(/[/\\]/g, ':').replace(name+'-','');
    depsList += '    debugCompile(project(path: "' + libName + '", configuration: "debug"))';
    insertExclude(p);
    depsList += '    releaseCompile(project(path: "' + libName + '", configuration: "release"))';
    insertExclude(p);

to:

    console.log('Subproject Path: ' + p);
    var libName=p.replace(/[/\\]/g, ':').replace(name+'-','');
    depsList += '    compile project(\'' + libName + '\')';
    insertExclude(p);

Works for me

jacruz
  • 56
  • 4
2

The trick is:

dependencies {
    // If the main app and wearable modules have the same flavors,
    // the following configuration uses automatic dependency matching.
    wearApp  project(':wearable')
}

You don't have t set flavor or type build now, gradle 3.0 and above search for each flavor and buildType. More info: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration#variant_dependencies

Leonardo Sapuy
  • 2,600
  • 2
  • 23
  • 30