Unlike web, android still lacks the ease of version deployments. Specially when you don’t want to use Play Store.
There will be five stages:
Versioning of application. For that we gonna use git revision and Major.Minor.Patch naming convention.
Building application using a docker. So that running environment doesn’t change.
Pushing new release to s3, while maintaining the previous versions.
Pushing new tag to git, with the new version. So, we’ll have tags for each version.
Basically, we gonna use docker, git, and some simple hacks to put things in work. In the end, I’ve shared a sample application.
Stage 1: Signing Our Application
It’s better to start thinking about security right from the big bang.
From android studio, you can generate a new keystore, a jks file. Help?
Copy the keystore file details in a config.yaml file like below:
Studio will take care of signing, but to generate signed apk from command line, you’ll need to make some changes in your build.gradle. The credentials we have put in above yaml file will be passed as command line args to gradle(Build stage).
Let’s dig into GitRevision
It counts the number of commits from git, so you’ll get incremental values everytime you release a new version. GitRevision will make versioning easy and consistent.
We’ll put the below code in build.gradle[app]
And in build.gradle[app]
Docker Image, Savage
We first need to build a docker image with minimum libraries and dependencies required.
Trollop will be helpful in compiling scripts, spicing the boring command line args.
We are using openjdk as base image for java environment and installed our sdk with version 27. You can change that accordingly.
Building the image:
Or you can directly pull my latest base image.
Docker container on the way
To automate the process, let’s dig into a small script:
Here we first check if the container already exists. Then create accordingly.
While creating the container, we mount our current project directory. So next time we run this container, our updated project will already be there in the container.
Stage 3: Running container, Build Stage
We run the container, with our compile script. Pass the signing config file we created earlier.
Stage 4: Pushing to S3
So, now we have build a signed apk from a docker container. It’s time to push them.
Connect with your s3 bucket and generate $HOME/.s3cfg file, and pass it to ruby script below:
application/vnd.android.package-archive is the apk file type descriptor.
Stage 5: Finally, Git Tagging The New Release Version, #hashtag