Android Gradle plugin sample

Plugin will upload apk to distribution system after building release artifact.

Create Project

In the gradle folder, copy samples->customPlugin->plugin to your work directory. Gradle distribution can be downloaded here.

Change build.gradle to this structure

Configure plugin and deploy to local folder

Rename and change plugin description file under src->main->resources->META-INF->gradle-plugins folder

File Name: com.tunebrains.beta-gradle-beta-upload.properties

Create groovy class com.tunebrains.beta.gradle.UploadApkPlugin

Specify folder to deploy plugin

Execute gradle task to upload archive. Refresh gradle task if required.

In app level build.gradle

Apply plugin:

Its time for write some code.

We will add custom tasks betaDebug and betaRelease to upload debug and release apks.

To perform multipart post add apache dependencies to build.gradle

To get resulting apk for upload we can use task field

Now we need to post our resulting apk to server endpoint.

In result of evecution uploadApk*we got the resulting json object of parsed server response. And can for example print to console url where you can find the build.

Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *