cannot change strategy of configuration ‘complie‘ after it has been resolved解决方案

这个也适用于configurationspileOnly configurations.xxCompileconfigurations.implementation configurations.xxImplementation等

这个也适用于configurationspileOnly configurations.xxCompile configurations.implementation configurations.xxImplementationConfiguration 对象出现该问题.

环境

  • migrate AndroidX后,gradle 版本:5.6.4, gradlePlugins版本:3.6.4

相关代码

task getLibs {
    configurations.compile.setCanBeResolved(true)
    configurations.compile.asFileTree.each { File file ->
        if (file.getName().matches(".*\\.zip")) {
            copy {
                from zipTree(file)
                into property_unzippedDir
            }
        }
    }
}

问题

在 sync gradle时 configurationspile.asFileTree 这段代码会报错:
cannot change strategy of configuration ‘complie’ after it has been resolved

解决方案

  • 上述代码改为:
task getLibs {
    configurations.compile.setCanBeResolved(true)
    configurations.compile.copy().asFileTree.each { File file ->
        if (file.getName().matches(".*\\.zip")) {
            copy {
                from zipTree(file)
                into property_unzippedDir
            }
        }
    }
}

在compile后面调用copy() 方法然后再调用asFileTree

原理

  • copy() 方法注解如下:

发布者:admin,转转请注明出处:http://www.yc00.com/web/1754915060a5214912.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信