Fast and lazy .apk distribution with Crashlytics

The hardest thing for me to do is to write release notes, and anyway, if I write commits for gradle, why not use them as release notes?

Luckily git allows that, and with gradle for android is there easy to write some small scripts and get the job done in one click.

Getting the release notes:

Since we need to properly add release notes since last distribution, a good way to control that is by tagging every time you release. This way you can add to release notes only the commits since the last tag.

To get all commits since last tag we can use the following command :

git log `git describe --tags --abbrev=0`..HEAD --oneline

This command contains an inner command to get the last tag:

git describe --tags --abbrev=0

In groovy to get the last tag write a function like that :

def getLastTag() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--abbrev=0'
standardOutput = stdout
}
return stdout.toString()
}

With that, we will get the last tag, and to get the commits the following function will do the job:

def getCommitsSinceLastTag() {
def range = getLastTag() + '..HEAD'
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log', range.toString().replace('\n', ''), '--oneline'
standardOutput = stdout
}
return stdout.toString()
}

Distribution with Crashlytics:

Let’s keep thing short, not much description for the above…

add the following tasks to build.gradle :

def groupName = "distribution"
task buildCandidate() {
group = groupName
dependsOn 'clean'
finalizedBy 'assembleDebug'
}
task sendCandidateToCrashlytics() {
group = groupName
dependsOn buildCandidate
finalizedBy 'crashlyticsUploadDistributionDebug'
}

and for release notes and the group to distribute :

debug {
ext.betaDistributionReleaseNotes = getCommitsSinceLastTag()
ext.betaDistributionGroupAliases="GroupName"
}

To release press the sendCandidateToCrashlytics task on the new gradle created group: