Not able to copy configurations dependencies after upgrading Gradle plugin for Android Studio to 3.0.1 and Gradle to 4.1

前端 未结 6 2032
野的像风
野的像风 2020-12-08 19:16

I used to copy \'compile\' dependencies to a specific folder using this simple gradle task :

task copyLibs(type: Copy) {
    from configurations.compile
             


        
相关标签:
6条回答
  • 2020-12-08 19:56

    I wanted to make a comment, but I'm still lacking the reputation required to do so (by one point!! >.< ). It doesn't look as if there's a way to acquire the list of implementation dependencies and the compileClasspath mentioned at the Gradle ticket Rafael posted won't work if you're working with Android directly, like my case where I need the dependencies to be exported so that Unity3D can package them up for release.

    So.. it looks like the only solution in this case is to use the deprecated compile type.

    0 讨论(0)
  • 2020-12-08 19:59

    I started getting this error after upgrading from gradle 5.5 to 5.6, and it happens when I try to sync the project in intelliJ.

    Thanks to this answer on another question, I solved it by applying the idea plugin to all projects and then running gradle cleanIdea and after that everything started working again.

    Another day, another #inexplicable solution to a problem.

    0 讨论(0)
  • 2020-12-08 20:01

    This probably won't help or have a better way to solve but...

    You can put your dependencies in a way that is possible to copy doing the following:

    android { ... }
    
    // Add a new configuration to hold your dependencies
    configurations {
        myConfig
    }
    
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.android.support:appcompat-v7:26.1.0'
        implementation 'com.android.support:support-v4:26.1.0'
        implementation 'com.android.support:design:26.1.0'
        implementation 'com.android.support.constraint:constraint-layout:1.0.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.1'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    
        // Now you have to repeat adding the dependencies you want to copy in the 'myConfig'
        myConfig fileTree(dir: 'libs', include: ['*.jar'])
        myConfig 'com.android.support:appcompat-v7:26.1.0'
        myConfig 'com.android.support:support-v4:26.1.0'
        ...
    }
    
    task copyLibs(type: Copy) {
        // Now you can use 'myConfig' instead of 'implementation' or 'compile' 
        from configurations.myConfig 
        into "$project.rootDir/reports/libs/"
    }
    

    This also helps if you have a Jar task that stops placing the dependencies in to the jar file because you changed from compile to implementation.

    You can use:

    from {configurations.myConfig.collect { it.isDirectory() ? it : zipTree(it) }}
    

    Instead of:

    from {configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }}
    
    0 讨论(0)
  • 2020-12-08 20:13

    instead of using configurations.implementation, the best option is to use: configurations.runtimeClasspath

    you can also think about: compileClasspath default

    0 讨论(0)
  • 2020-12-08 20:18

    Another suggestion.

    I created my custom config and then used it as configurations.customConfig:

    configurations {
      customConfig.extendsFrom implementation
    }
    

    The copy task must be correspondingly edited:

    task copyLibs(type: Copy) {
        from configurations.customConfig
        into "$project.rootDir/reports/libs/"
    }
    
    0 讨论(0)
  • 2020-12-08 20:19

    I make configuration can resolved, so no exception get dependcenies's file

    configurations.implementation.setCanBeResolved(true)
    configurations.api.setCanBeResolved(true)
    
    println configurations.implementation.resolve()
    println configurations.api.resolve()
    
    0 讨论(0)
提交回复
热议问题