我如何知道 android gradle 插件的 applicationVariants 中的属性?

How do I know the properties in applicationVariants of android gradle plugin?

我正在使用带有 gradle 插件的 Android Studio 来开发应用程序。我在 DSL Reference 上学习了 android gradle 插件的一些用法。但我发现的一件事是 doc 上的 applicationVariants 部分很难理解。只给出了这样的描述:

DomainObjectSet<ApplicationVariant> applicationVariants

The list of Application variants. Since the collections is built after evaluation, it should be used with Gradle's all iterator to process future items.

但是 ApplicationVariant 中的属性是什么?我不知道。而且我没有找到任何参考 link 来描述 ApplicationVariant。

仅在页面最底部的 Gradle Plugin User Guide 中。它记录了 applicationVariants、libraryVariants 和 testVariants 中的可用属性。但是我发现其中有相当一部分属性已经弃用了很长时间,Android 没有更新此页面。

那么我在哪里可以找到 ApplicationVariant 中最新的属性?

https://android.googlesource.com/platform/tools/build/+/8dca86a/gradle/src/main/groovy/com/android/build/gradle/internal/ApplicationVariant.groovy

我也好不容易才找到。这是它移动的界面: 它还将包含您在自己的风格中定义的任何道具,例如 versionName、applicationId 等

public interface ApplicationVariant {
    String getName()
    String getDescription()
    String getDirName()
    String getBaseName()
    VariantConfiguration getConfig()
    boolean getZipAlign()
    boolean isSigned()
    boolean getRunProguard()
    FileCollection getRuntimeClasspath()
    FileCollection getResourcePackage()
    Compile getCompileTask()
    List<String> getRunCommand()
    String getPackage()
    AndroidBuilder createBuilder(AndroidBasePlugin androidBasePlugin)
}

并打印任何对象的道具:

def filtered = ['class', 'active']

println theObject.properties
            .sort{it.key}
            .collect{it}
            .findAll{!filtered.contains(it.key)}
            .join('\n')

@CaptRespect 的回答中的 link 是针对特定版本的。这是主分支中 public API 的 link:

/gradle/api/ApplicationVariant.java
(起源自) /gradle/api/ApkVariant.java
(起源自) /gradle/api/BaseVariant.java

这里有一些关于这些的文档: