On Android Gradle build.gradle What is "it" in it.buildConfigField?

I have the official Gradle website and the official Android developer site, but could not find the answer to this question.

  • In android build.gradle, what is that "this". in the next buildConfigField method? Is this an instance of an object?

I found that moving the buildConfigField method to its default value, Conff allows me to use the method without "it."

  1. What is the difference between the two? Why can I use one method over another?

    android { ... defaultConfig { ... buildConfigField 'String', 'API_KEY', MyApiKey } buildTypes { release { ... } } buildTypes.all { ... } buildTypes.each { ... it.buildConfigField 'String', 'API_KEY', MyApiKey } } 
+7
android groovy gradle
source share
1 answer

Gradle build scripts extended by Groovy scripts. When you see β€œthis” in a Groovy script or Gradle build script, it represents the object that was passed in closure. In your example, the closure is "{...}", which was passed to "everyone." Thus, it iterates through the assembly "buildTypes" (or something that iterates), passes each record in closure, and refers to the passed object as "he". You can change the name of the object passed to the closure, but by default it is "it".

+5
source share

All Articles