jay*_*ubi 9 groovy gradle android-studio build.gradle
我正在使用Android Studio和gradle构建脚本.当我要更改某些设置时,我需要all
一些字段.但我不是很清楚each
之间applicationVariants
和all
.
例如,我用google搜索一些代码来更改输出apk文件名.代码迭代variant.outputs
by each
和all
by each
:
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, "MyApp.apk")
}
}
Run Code Online (Sandbox Code Playgroud)
each
是一个简单的常规结构。它用于迭代给定的对象,不修改它(原始对象)并在完成后返回(未更改的)对象。看:
assert [1, 2, 3] == [1, 2, 3].each { println it }
Run Code Online (Sandbox Code Playgroud)
whileall
是gradle自己添加的一个方法。所以,android
插件添加了这个扩展,它有getApplicationVariants
方法。由于groovy允许省略get
,所以applicationVariants
可以使用。现在,提到的扩展使用此类来保存变体集合,该集合扩展了 - this。在后一个all
方法中定义的,据我所知它只是一个批处理。
归档时间: |
|
查看次数: |
1456 次 |
最近记录: |