Gradle plugin for TestFlight

Sep 13, 2013

Since august I’ve got a new job. We are currently a team of three developers working on a client/server application. The server is developed in Rails. The client is developed on the Android platform.
A few months ago Google decided to use the excellent Gradle build system as its tool for building Android applications, instead of Ant + Ivy combo. I really see it as a huge improvement. I won’t discuss the pros and cons of Gradle here, there are plenty of resources on that topic on the web.

Gradle makes it easy to add custom tasks and plugins, and that’s what I want to discuss here.

You can find the code of this plugin on Github but keep in mind that it’s not working at the time of this writing.

FlightTest

We use FlightTest in order to upload beta builds of our app. Needless to say, we’d like to automate it.
So it’s a good opportunity to dust off my Groovy skills which I haven’t practiced a lot recently, I have to admit.

Note: of course I could use Java as language for developing this plugin, since I’m primarily a Java developer, but I feel more productive when writing code in Groovy.

First things first : the task

We’ll start by writing a task whose goal is to upload an APK file to TestFlight, which is, in the end, what we want to achieve.

TestFlight has an API for uploading APK’s. It’s very easy. The only thing to note is that the content-type of the request is multipart/form-data.

So it should quite simple to write a Gradle task that uploads the build to TestFlight.
For this, I’ll use the excellent HttpBuilder.

It is to be noted that I haven’t handled the exceptions. It is on my to-do list.

You could use this task as-is, without encapsulating it in a plugin, just like this :

// rest of build.gradletaskuploadToTestFlight(type:TestFlightUploadTask,group:'deploy',description:'Upload Staging APK to TestFlight',dependsOn:assembleStaging){apkFilename='build/apk/my-android.apk'apiToken='**************'teamToken='**************'notes='Just a release'distributionLists=['Developers']notify=true}

and it would work. Actually that’s what I did until now.

But some things could be improved. For example I’d like to be able to create a task for each build variant, for example uploadToTestFlightStaging. But in order to be able to dynamically generate the upload tasks I need to know when the build variants are generated, thus I need to extend the Android plugin.

I’ve looked at the Android plugin source code and must say it’s intimidating, I don’t understand all the ins and outs yet.

And that’s why I asked mentoring. I hope to be able to have a fully working - with error handling, tests, and deployment - within a week or two.