- 1 year ago 78
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?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download