gpt4 book ai didi

android - 如何检查属性 `applicationVariants` 的 gradle?

转载 作者:行者123 更新时间:2023-11-29 01:00:11 25 4
gpt4 key购买 nike

我有一个与 this question 类似的问题

Could not get unknown property 'applicationVariants' for object of type com.android.build.gradle.LibraryExtension.

我正在尝试检查此属性并如果我有它。我以为我可以关注 this answer :

// for application modules
if (project.hasProperty('applicationVariants')) {
println "has applicationVariants"
android.applicationVariants.all { variant ->
// ... do something
}
}

// for library modules
if (project.hasProperty('libraryVariants')) {
println "has libraryVariants"
android.libraryVariants.all { variant ->
// ... do something
}
}

但是我没有看到任何打印语句,也没有任何内部代码在执行。我错过了什么?

最佳答案

这些是 project.android 的属性 - 在任务 afterEvaluate 中它们有一个值。

task afterEvaluate {

if(project.android.hasProperty('applicationVariants')) {
println("*** has applicationVariants")
}

if(project.android.hasProperty('libraryVariants')) {
println("*** has libraryVariants")
}
}

关于android - 如何检查属性 `applicationVariants` 的 gradle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51795897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com