Git Product home page Git Product logo

androidversion's Introduction

Android Version plugin

Android Version plugin is a gradle plugin that helps managing version for Android projects. Plugin is especially helpful when you are dealing with complex build structure with multiple flavors and apk splits.

Features

  • Version name and code manipulation
  • Per flavor & build type version manipulation
  • Per split version manipulation
  • Multi dimensional flavor version manipulation
  • Rule based automatic version code calculation
  • Rename apk file name

Usage

Apply plugin

plugins {
    id("si.kamino.version")
}

or

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
         classpath "gradle.plugin.si.kamino.gradle:android-version:1.8.1"
    }
}

apply plugin: "si.kamino.version"

Configuration

androidVersion {

    fileNamePattern 'sample-$flavors.dimension-$versionName'

    appVersion {
        major 1
        versionCode {
            digits 2
        }
    }

    variants {
        variant1 {
            minor 2
        }

        variant2 {
            minor 5
        }
        
        debug {
            build 1
        }
        
        variant1Debug {
            build 3
        }

    }
    
    splts {
        abi {
            x86 {
                versionCode(IncreaseVersionCode) {
                    by 1000000
                }
            }
        }
    }

}

Flavor combinations

Beside configuring version based on flavors and build types you can also do that on combinations of them when using multiple variant dimensions. Combinations are calculated based on dimension order. For example if you have flavor1 and flavor2 that are in different dimensions you could do configuration for flavor1Flavor2 and also flavor1Flavor2Debug. If you define both second one will override first one if they have sem properties set.

Version code types

Based on your need you can specify version code tactics that you want to use. By default appVersion uses SimpleVersionCode tactics but this can easily be changed. Version code tactics can also be changed per variant/split. It can ether modify existing version code or specify completely new value.

  • SimpleVersionCode creates version code from version name parameters (major, minor and build). By default each part will take up 2 digits but this is configurable through digits parameter.
  • IncreaseVersionCode Similar than SimpleVersionCode but you can specify digits per each part.
  • StaticVersionCode sets static value defined in versionCode parameter.
  • IncreaseVersionCode increases previously calculated value by value defined in by parameter.

By default plugin will set SimpleVersionCode with digits set to 2.

Output file name

With fileNamePattern property you can easily rename out apk files. Alongside static values you can specify template and plugin will generate the file name. Available properties are:

  • project: name of the project. In case of default Android Studio template that would be app.
  • variantName: full unique name of the variant including filters.
  • buildType: build type of the variant
  • flavorName: name of all flavors combined with capitalized latter
  • versionCode: version code of output file including apk splits
  • versionName: version name of output file including apk splits
  • flavors by dimension map of all flavors. (for example: flavors.dimension)

.apk suffix is automatically added at the end of file name.

Limitations

Due to the changes in Android Gradle plugin 3.0.0, Android version plugin 1.2.3 or above is required. Android version plugin is fully backwards compatible and new version will work with old version of Android gradle plugin.

There are some instant run limitations in versions before 2.3.0 of Android Gradle plugin due to bug. Due to this issue plugin will be disabled if it detects that it is running under instant run. That means that version name will be empty and version code will be 0. That is ok for tho most cases, if not you can still set version the old way in android.defaultConfig. When using Android Gradle Plugin 2.3.0 or newer everything works as espected.

License

MIT License

Copyright (c) 2017 Kamino d.o.o.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

androidversion's People

Contributors

blazsolar avatar ribafish avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.