I'm in a weird problem here.
Here's the part of the gradle script that actually needs fixing
def getVersion() {
def Calendar cal = Calendar.getInstance();
//def SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
def SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
def int releaseNumberOfTheDay = 1;
def char versionLtr = ext.vLetter; //line 136, the error line
def StringBuilder sb = new StringBuilder();
//sb.append("RC4 ");
sb.append("2.1");
sb.append(" (");
sb.append(dateFormat.format(cal.getTimeInMillis()));
//sb.append(versionLtr);
sb.append(releaseNumberOfTheDay);
sb.append(")");
//sb.append("a");
return sb.toString();
}
What I'm trying to do here is assign a version letter based on the used flavor. I have added the vLetter
to extensions ext
and that one works fine. What I'm really having a problem with is, referencing extension and plain gradle members/fields from within gradle.
I have three flavours, DEV, STAGE and LIVE. and this getVersion()
function is referenced by
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 50 // hockeyapp
versionName getVersion()
}
the client wants a letter in the version name so he can tell them apart.
I tried this, an extension member to hold the letter for me:
productFlavors {
SOAP_DEV_ {
applicationId "com.my.name"
resValue "string", fbMeta, "DEV_"
ext.fbMeta = 'DEV_'
ext.vLetter = 'D'
}
SOAP_STAGE_ {
applicationId "com.my.name"
resValue 'string', fbMeta, "STAGE_"
ext.fbMeta = 'STAGE_'
ext.vLetter = 'S'
}
SOAP_LIVE_ {
applicationId "de.real.name"
resValue 'string', fbMeta, "LIVE_"
ext.fbMeta = 'LIVE_'
ext.vLetter = 'L'
}
}
But the letter is invisible in the getVersion()
declaration. It's as if that function is compiled (or ran?) before the rest of the file, as the error I'm getting is
Error:(136, 0) Cannot get property 'vLetter' on extra properties extension as it does not exist
Soo... please guys (and gals ofc), how do I fix this? I really need to get that letter into the version number somehow.
EDIT:
The problem is actually this, no task actually start running. So I'm not sure if the doFirst
trick will help me. But i'm open for suggestions. It really doesn't even have to be in the extensions, I just thought of that first. If there is a way for me to "pass" variables from gradle code to the getVersion() function, I'm fine with that. I'm using the ext.vLetter here as a carrier really. I don't need it visible in java or at runtime.
10:29:47 AM Gradle sync started
10:29:54 AM Gradle sync failed: Cannot get property 'vLetter' on extra properties extension as it does not exist Consult IDE log for more details (Help | Show Log)