I'm working in Android Studio 0.8.6
End Goal
Have 3 variants - Noopt, Debug, Release - that set a variable's value based on which variant is being built. For example, if I was building a Noopt build, the string mode
should be equal to noopt
.
Current Implementation
Here's what I'm trying right now.
buildTypes {
release {
debuggable false
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.packageRelease
mode = "release"
println("In RELEASE")
}
noopt {
debuggable true
jniDebugBuild true
renderscriptDebugBuild false
runProguard false
zipAlign true
mode = "noopt"
println("In NOOPT")
}
}
I declare mode outside of android by doing
def mode = ""
However, no matter what variant I build with, mode
is always set to noopt
. If I add more variants, the variable is always set to whatever the last variant is.
Is my understanding of how gradle works incorrect? I would have assumed that it would only run the code for the variant you're building, but it appears to run it for every variant - or at least any non-standard Android properties/code get run no matter what.
Is there some other way I should be doing this?
Edit:
To add some more context, here's what I want in the end:
task runCustomScript(type:Exec) {
def mode = ""
if (currentBuildType == debug)
mode = "DEBUG=1"
else if (currentBuildType == noopt)
mode = "NOOPT=1"
/* etc etc etc */
executable "myExec"
args "-C", "blahblahblah", mode
}
So what I need is a way to find the current variant or build type being run from within a task.