Android 与应用插件类似,添加一系列定制gradle脚本的相应方式是什么?

Android 与应用插件类似,添加一系列定制gradle脚本的相应方式是什么?,android,gradle,Android,Gradle,在应用程序级别的gradle中,我们可以执行以下操作: plugins { id 'com.android.application' id 'kotlin-android' ... } 然而,我有一些我想要应用的自定义gradle脚本。目前,我可以在该块下面复制这些内容,例如: plugins { id 'com.android.application' id 'kotlin-android' } apply from: "$rootDir/g

在应用程序级别的gradle中,我们可以执行以下操作:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    ...
}
然而,我有一些我想要应用的自定义gradle脚本。目前,我可以在该块下面复制这些内容,例如:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}
apply from: "$rootDir/gradle/helpers/common-methods.gradle"
foo {
   from: "$rootDir/gradle/helpers/common-methods.gradle"
}
这很好,但我想知道是否有相应的块/闭包类型的方法来添加这些,比如:

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}
apply from: "$rootDir/gradle/helpers/common-methods.gradle"
foo {
   from: "$rootDir/gradle/helpers/common-methods.gradle"
}

我并不特别需要这个,只是感兴趣,我找到了答案

apply {
from "$rootDir/gradle/helpers/common-methods.gradle"
}
请确保使用空格,不要使用from:

使用
from:
会给您一个非常详细的错误:

Statement labels may not be used in build scripts.
In case you tried to configure a property named 'from', replace ':' with '=' or ' ', otherwise it will not have the desired effect.

在这种情况下,解决方案是只使用一个空格

我对gradle了解不多,我有一些自定义脚本,但没有什么大的,如果这是重复的,我很抱歉:)我想你(读:
apply{from:…}
)嗨@Zoe,我在发布问题之前,实际上已经尝试过搞乱它,最后找到了一些有效的方法,假设我现在可以把这当作一个问答