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.
Solution 1:
With AndroidStudio 2.1.1, you can use the idea.platform.prefix property:
defsysprops= System.getProperties()
if (sysprops['idea.platform.prefix'] != null) {
// Built from AndroidStudio
} else {
// Built from command line
}
Solution 2:
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.
Updated:
OK I found the direct way :)
defenv= System.getProperties()
if (env['com.android.studio.gradle.project.path'] != null) {
// build from Android Studio, do magic here
}
Solution 3:
Jake Wharton suggests android.injected.invoked.from.ide
to speed butterknife at development time by using reflection:
dependencies {
if (properties.containsKey('android.injected.invoked.from.ide')) {
implementation 'com.jakewharton:butterknife-reflect:<version>'
} else {
implementation 'com.jakewharton:butterknife:<version>'
kapt 'com.jakewharton:butterknife-compiler:<version>'
}
}
From Twitter:
Hey ButterKnife users: I'm working on a reflection-based implementation for use during development so the annotation processor is not needed.
A follow-up:
What is this? A property from (link: http://gradle.properties) gradle.properties?
The answer we want:
No it's added by the IDE
Post a Comment for "How To Tell When Gradle Is Being Run From Androidstudio?"