访问 buildSrc 中的应用程序变体



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

buildSrc/BuildTypes.kt 中的示例代码块

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)
}
}
}

app.gradle.kts中的示例代码块(我想实现相同的效果 在构建中(

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>

最新更新