Gradle error: configuration declares dependency which is not declared

前端 未结 5 1318
悲哀的现实
悲哀的现实 2020-12-05 18:31

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 pr         


        
相关标签:
5条回答
  • 2020-12-05 18:47

    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
    
    0 讨论(0)
  • 2020-12-05 18:51

    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

    0 讨论(0)
  • 2020-12-05 19:03

    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

    0 讨论(0)
  • 2020-12-05 19:10

    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')
    
    0 讨论(0)
  • 2020-12-05 19:11

    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')
    }
    
    0 讨论(0)
提交回复
热议问题