0

In Android development, we use gradle building system. We often see some usual codes in build.gradle:

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    testOptions {
        unitTests.returnDefaultValues = true
    }

    defaultConfig {
        applicationId "xxx"
        minSdkVersion 19
        targetSdkVersion 28 

We also see some unusual codes like:

javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["xxx": "xxx"]
            }
        }

applicationVariants.all { variant ->
        buildType = variant.buildType.name // Sets the current build type
    } 

How do you know there's a buildType variable of variant? What's the object of variant? Can I see its details?

We often copy/paste those codes from internet without thinking too much, so we don't have a systematic knowledge of these declarations and variables.

I wonder if there is some documents and/or codes of such things? So that we can search like in a Javadoc, and write gradle files more freely, instead of just copy/paste.

I know there are two site:

http://google.github.io/android-gradle-dsl/current/index.html

http://google.github.io/android-gradle-dsl/javadoc/current/

But they don't clarify why there's the variant.buildType definition. You may find in the following class:

http://google.github.io/android-gradle-dsl/javadoc/current/com/android/build/api/variant/VariantInfo.html

there is a definition:

getBuildTypeName()

You may think variant.buildType is from this.

BUT. getFlavorNames() returns a list, while variant.flavorName is a string.

So, the above 2 documents are not enough, I believe.

Community
  • 1
  • 1
McArthor Lee
  • 183
  • 12
  • Possible duplicate of [How do I know the properties in applicationVariants of android gradle plugin?](https://stackoverflow.com/questions/36672469/how-do-i-know-the-properties-in-applicationvariants-of-android-gradle-plugin) – Lukas Körfer May 21 '19 at 00:58
  • @LukasKörfer I don't agree with the accepted answer of that post... as i said in my post, variant.flavorName is a string, while getFlavorNames() returns a list. So i think the java does not match the real code in build.gradle. – McArthor Lee May 21 '19 at 10:14
  • As you can see in the linked answer, `variant` is of type `ApplicationVariant`. – Lukas Körfer May 21 '19 at 10:19
  • @LukasKörfer yes i've read that post. but i didn't find anything about the `flavorName` variable definition, or something looking like it? – McArthor Lee May 22 '19 at 02:52
  • Take a look at the second answer. It links the code of the interface `ApplicationVariant` and the two interfaces it extends from. The interface `BaseVariant` defines a method `getFlavorName()`, which can be accessed via `flavorName` in Groovy. – Lukas Körfer May 22 '19 at 08:43
  • @LukasKörfer yes i've seen that. many thanks. is there any javadoc for the API? – McArthor Lee May 23 '19 at 01:14

0 Answers0