- 6 months ago 28
Android Question

How to tell when gradle is being run from AndroidStudio?

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") 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[''] != null) {
    // build from Android Studio, do magic here