在我的应用程序中,我管理Gradle中的所有buildSrc内容。其中之一是buildTypes。我能够访问buildTypes提供的所有属性。但是,我无法访问applicationVariants中的buildSrc。有什么办法吗?


internal object Debug : BuildTypeCreator {
    override val name = InternalBuildType.DEBUG

    override fun create(
        namedDomainObjectContainer: NamedDomainObjectContainer<BuildType>,
        project: Project,
        isLibrary: Boolean,
        closure: BuildType.() -> Unit
    ): BuildType {
        return namedDomainObjectContainer.maybeCreate(name).apply {
            if (isLibrary) {
                versionNameSuffix = "-dev-${project.gitSha}"
            } else {
                applicationIdSuffix = ".dev"
            }
            isTestCoverageEnabled = true
            isMinifyEnabled = false
            isDebuggable = true
            closure.invoke(this)
        }
    }
}


applicationVariants.all { -> **This is not accessible in buildSrc**
                if (buildType.name == getByName("release").name) {
                    outputs.all { output: BaseVariantOutput ->
                        val outputImpl = output as BaseVariantOutputImpl
                        outputImpl.outputFileName = "calendar-view.apk"
                        true
                    }
                }
            }

提前致谢。

最佳答案

好的,我通过传递参数domainObjectSet: DomainObjectSet<ApplicationVariant>解决了它

10-04 10:32