11

One Click Deployment for android developers

 3 years ago
source link: https://medium.flatstack.com/one-click-deployment-for-android-developers-ab0a126f5db2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

One Click Deployment for android developers

Image for post
Image for post

We have a node project in our team that uses Yarn package manager. Yarn has a convenient command called yarn version that bumps app version number and adds a git tag. We also have a script that invokes that command and then pushes changes with the git tag to the Github. Then Circleci detects the changes and deploys new version to the staging environment. All that gets done with a single click of a mouse or invocation of a command in the terminal, it removes the risk of forgetting to add a tag or bumping the app version and helps developer to concentrate on more interesting parts of work.

Unfortunately, Gradle doesn’t have such a feature out of the box, that is how the idea to write a one click deployment plugin have been born. To be fair the idea isn’t exactly new, as we already had a comparable functionality in our android project, but it was implemented as Gradle script plugin, which is less convenient if you want to reuse it in another project, as a standalone plugin would let you to just import it by adding a couple of new lines in the Gradle build config.

Setup

To import the plugin to your project you will need to add plugin dependency to your project’s Gradle config file:

dependencies: {

classpath ‘com.github.AntonChaynikov.oneclickpublish:oneclickpublish:0.12.0’

}

And apply the plugin in the app module’s Gradle config file:

apply plugin: ‘com.antonchaynikov.oneclickpublish’

Synchronize Gradle with the project’s files and a new Gradle task group named ‘oneclickpublish’ should appear among the available tasks.

Image for post
Image for post

The group will contain 3 new tasks that will bump major, minor or patch version of your app. The versioning follows semver pattern. The last step is to create or modify the main module’s gradle.properties file. The file should contain lines with the current build version name and version code:

appVersionName=1.0.0
appVersionCode=1000000

The plugin supports a little bit of customization — you are able to choose branches that you can update version from and the remote repo’s name to push the changes to. By default the branch name is ‘master’ and remote repo name is ‘origin’. To configure branches and remote you can add an extension to your modules build.gradle file:

oneClickPublish {
branchNames = [“master”]
remoteRepoName = “origin”
}

Usage

After the steps described above you should be able to bump the app’s version and push changes to the git repository using just one command. The plugin will increase one of the version segments and calculate the version code accordingly.

The version code is calculated by the following formula:

code = Major * 100000 + Minor * 1000 + Patch

Ideally, the project should be integrated with one of the ci/cd services that would detect pushed tag and deploy associated version to the Google Play Alpha and/or to Firebase App Distribution for example.

Feel free to use or modify it as much as you like.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK