如何判断 gradle 何时从 AndroidStudio 运行? [英] How to tell when gradle is being run from AndroidStudio?
问题描述
我需要在我的 gradle 构建文件中构建一些 hack,以便 Android Studio 理解一些东西.当我从命令行目录运行构建时,我不需要这些技巧.有没有办法检测何时从 Android Studio 中运行构建?也许通过环境变量等?
I need to build some hacks into my gradle build file so that Android Studio understands some things. I don't need these hacks when I run the build from the command line directory. Is there a way to detect when the build is being run from within Android Studio? Maybe through environment variables, etc?
推荐答案
Use gradle -P blah=val
from command line and in your build.gradle use project.hasProperty("blah")
或 project.getProperty("test")
或 if (blah ... )
来决定是否运行你的 hack.
Use gradle -P blah=val
from command line and in your build.gradle use project.hasProperty("blah")
or project.getProperty("test")
or if (blah ... )
to decide whether run your hack or not.
更新:
好的,我找到了直接的方法:)
OK I found the direct way :)
def env = System.getProperties()
if (env['com.android.studio.gradle.project.path'] != null) {
// build from Android Studio, do magic here
}
这篇关于如何判断 gradle 何时从 AndroidStudio 运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!