I am having an issue with gradle and Android Studio, which only appears when building in Android Studio (BuildServer and Commandline work just fine)
applicationVariants.all { variant ->
def file = variant.outputFile
variant.outputFile = new File(file.parent, file.name.replace("app-", getDate() + "_myapp_" + getGitCommit() +"_"));
}
def getDate() {
def dateNow = new Date()
def formattedDate = dateNow.format('yyyy-MM-dd_HH-mm-ss')
return formattedDate
}
The build works, but when AS wants to copy the apk to the device it throws a Local path doesn't exist.
error.
The problem is that the files that are generated look like:
2014-03-17_16-17-41_myapp__debug-unaligned.apk
but AS looks for:
2014-03-17_16-17-18_myapp__debug-unaligned.apk
which is somehow generated by an AS specific build step resulting in a recalculation of the date. I tried to fix it with an external property for the build date which should remain the same throughout the build process, but probably due to my lack of gradle skills, this did not help.
Maybe someone has a workaround for me to make my build work in Android Studio.