admin管理员组

文章数量:1566600

这个也适用于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() 方法注解如下:

本文标签: 解决方案StrategyChangeconfigurationresolved