【问题标题】:How can I check gradle for property `applicationVariants`?如何检查属性`applicationVariants`的gradle?
【发布时间】:2019-01-18 14:58:03
【问题描述】:

我和this question有类似的问题

无法为 com.android.build.gradle.LibraryExtension 类型的对象获取未知属性“applicationVariants”。

我正在尝试检查这个属性并做一些事情如果我有它。我以为我可以关注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
    }
}

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

【问题讨论】:

    标签: android gradle android-gradle-plugin


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-08-08
      • 2017-12-19
      • 2015-09-26
      • 2020-05-03
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多