在 buildSrc 中访问 ApplicationVariants
Access ApplicationVariants in buildSrc
在我的应用程序中,我管理 buildSrc
中的所有 Gradle
内容。其中之一是 buildTypes
。我能够访问 buildTypes
提供的所有属性。但是,我无法访问 buildSrc
中的 applicationVariants
。有什么办法吗?
Sample code block in 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)
}
}
}
Sample code block in app.gradle.kts(which I want to achieve the same
in buildSrc)
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>
在我的应用程序中,我管理 buildSrc
中的所有 Gradle
内容。其中之一是 buildTypes
。我能够访问 buildTypes
提供的所有属性。但是,我无法访问 buildSrc
中的 applicationVariants
。有什么办法吗?
Sample code block in 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)
}
}
}
Sample code block in app.gradle.kts(which I want to achieve the same in buildSrc)
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>