gradle-android-git-version


Source link: https://github.com/gladed/gradle-android-git-version

gradle-android-git-version

A gradle plugin to calculate Android-friendly version names and codes from git tags.

If you are tired of manually updating your Android build files for each release, or generating builds that you can't trace back to code, then this plugin is for you!

Installation and Use

Add the plugin the top of your app/build.gradle (or equivalent):

plugins {

  id 'com.gladed.androidgitversion' version '0.4.0' 
}

Set versionName and versionCode from plugin results:

android {

  // ...
  defaultConfig {

// ...

versionName androidGitVersion.name()

versionCode androidGitVersion.code()

Use a git tag to specify your version number (see Semantic Versioning)

$ git tag 1.2.3 $ gradle --quiet androidGitVersion androidGitVersion.name 1.2.3 androidGitVersion.code 1002003

For more advanced usage, read on...

Tag format

Tags should look like 1 or 3.14 or 1.12.5. There must be at least one tag of this format reachable from the current commit, or the generated version name will be "unknown".

Any suffix after the version number in the tag (such as -release4 in 1.2.3-release4) is included in the version name, but is ignored when generating the version code.

In some cases, you'll have more than one version being generated in a single repo. In this case you can supply a prefix like "lib-" to separate sets of tags. See prefix below for more.

Intermediate Versions

Builds from non-tagged commits will generate a name() something like this:

1.2.3-2-93411ff-fix_issue5-dirty

In the example above, the components are:

1.2.3 -2 -93411ff -fix_issue5 -dirty
Most recent tag Number of commits since tag Commit SHA prefix Branch name Dirty indicator

Branches listed in hideBranches won't appear.

"-dirty" will only appear if the current branch has uncommitted changes.

You can customize this layout with format (see below).

Version Codes

Version codes are calculated relative to the most recent tag. For example, version 1.2.3 will have a version code of 1002003.

You can customize the scheme used to generate version codes with codeFormat (see below).

Methods

name() returns the current version name.

code() returns the current version code.

flush() flushes the internal cache of information about the git repo, in the event you have a gradle task that makes changes to the repo.

Tasks

androidGitVersion prints the name and code, as shown above.

androidGitVersionName prints only the name.

androidGitVersionCode prints only the code.

Configuration Properties

You can configure how names and codes are generated by adding an androidGitVersion block to your project's build.gradle file, before the android block. For example:

androidGitVersion {

  abis = ["armeabi":1, "armeabi-v7a":2 ]
  baseCode 200000
  codeFormat 'MNNPPP'
  format '%tag%%.count%%<commit>%%-branch%%...dirty%'
  hideBranches = [ 'develop' ]
  onlyIn 'my-library'
  prefix 'lib-'
  tagPattern /^R[0-9]+.*/
  untrackedIsDirty = false 
}
  android {

  ... 
}
 

abis (map of String:int)

abis indicate how ABI platforms are mapped to integer codes. These integer codes are inserted into the A place in codeFormat.

The default abis are:

['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9 ] 

baseCode (int)

baseCode sets a floor for all generated version codes (that is, it is added to all generated version codes). Use this when you have already released a version with a code, and don't want to go backwards.

The default is baseCode 0, enforcing no minimum version code value.

codeFormat (string)

codeFormat defines a scheme for building the version code. Each character corresponds to a reserved decimal place in the resulting code:

  • M for the Major version number (1.x.x)
  • N for the Minor version number (x.1.x)
  • P for the Patch version number (x.x.1)
  • B for the build number (revisions since last tag)
  • A for the ABI platform code [1]
  • X for a blank place filled with 0

[1] if you use A you must call variants to tell the plugin about your project's build variants. For example:

android {

  ...
  androidGitVersion {

codeFormat = 'AMNNPPP'

variants applicationVariants
  
}
 
}
 

Note that changing the version code scheme for a released Android project can cause problems if your new version code does not increase monotonically. Consider baseCode if you are changing code formats from a prior release.

Android version codes are limited to a maximum version code of 2100000000. As a result, codeFormat only allows you to specify 9 digits.

The default is codeFormat 'MMMNNNPPP', leaving 3 digits for each portion of the semantic version. A shorter code format such as MNNPPP is highly recommended.

hideBranches (list of strings/regexes)

hideBranches identifies branch names to be hidden from the version name for intermediate (untagged) commits.

For example, if 'master' is your development branch, hideBranches ['master'] results in build names like 1.2-38-9effe2a instead of 1.2-38-master-9effe2a.

Note that each element of hideBranches is interpreted as a regex pattern, for example, [ 'master', 'feature/.*' ].

The default is hideBranches [ 'master', 'release' ], meaning that intermediate builds will not show these branch names.

format (string)

format defines the form of the version name.

Parts include:

  • tag (the last tag)
  • count (number of commits, if any, since last tag)
  • commit (most recent commit prefix, if any, since the last tag)
  • branch (branch name, if current branch is not in hideBranches)
  • dirty (inserting the word "dirty" if the build was made with uncommitted changes).

Parts are delimited as %<PARTNAME>%. Any other characters appearing between % marks are preserved.

Parts are sometimes omitted (such as a branch name listed by hideBranches). In this case the entire part will not appear.

The default is format "%tag%%-count%%-commit%%-branch%%-dirty%"

onlyIn (string)

onlyIn sets a required path for relevant file changes. Commits that change files in this path will count, while other commits will be ignored for versioning purposes.

For example, consider this directory tree:

+-- my-app/
  +-- .git/
  +-- build.gradle
  +-- app/
  |
+-- build.gradle
  |
+-- src/
  +-- lib/

+-- build.gradle

+-- src/ 

If my-app/lib/build.gradle is configured with onlyIn 'lib', then changes to files in other paths (like my-app/build.gradle or my-app/app/src) will not affect the version name.

The default is onlyIn '', including all paths.

prefix (string)

prefix sets the required prefix for any relevant version tag. For example, with prefix 'lib', the tag lib-1.5 is used to determine the version, while tags like 1.0 and app-2.4.2 are ignored. When found, the prefix is removed from the front of the final version name.

The default is prefix '', matching all numeric version tags.

tagPattern (string/regex)

tagPattern limits the search for the most recent version tag to those that match the pattern. For example, tagPattern /^v[0-9]+.* limits matches to tags like v1.6.

If both prefix and tagPattern are used, the prefix strings should be included in the tagPattern.

The default is tagPattern /^$prefix[0-9]+.*/, finding all tags beginning with the prefix (if specified) and a digit.

untrackedIsDirty (boolean)

When untrackedIsDirty is true, a version is considered dirty when any untracked files are detected in the repo's directory.

The default is untrackedIsDirty false; only tracked files are considered when deciding on "dirty".

Deprecated Configuration Properties

Deprecated properties are supported but may be dropped in a future release. Transition your project to a supported property as soon as possible.

multiplier (int) (deprecated)

Use codeFormat instead.

multiplier sets the space allowed each part of the version when calculating the version code.

For example, if you want version 1.2.3 to have a version code of 100020003 (allowing for 9999 patch increments), use multiplier 10000.

Use caution when increasing this value, as the maximum version code is 2100000000 (the maximum integer).

The default multiplier is 1000.

parts (int) (deprecated)

Use codeFormat instead.

parts sets the number of parts the version number will have.

For example, if you know your product will only ever use two version number parts (1.2) then use parts 2.

Use caution when increasing this value, as the maximum version code is 2100000000 (the maximum integer).

The default number of parts is 3.

License

All code here is Copyright 2015-2017 by Glade Diviney, and licensed under the Apache 2.0 License.

Resources

A lightweight, good expandability android library used for displaying different load pages like loading, error, empty, timeout or your custom load page when you do net job.

Android widget to present calendar in a recycler view. The idea was to replicate calendar the way calendar is presented in the amazing Airbnb app.

Konveyor is a tiny library which intends to battle RecyclerView.Adapter Hell by introducing "Composition over inheritance" approach when dealing with RecyclerView adapters. While making your Adapter related logic testable by providing abstraction layer over its logic, it will make you forget all of the ViewType hassle all together.

Secure and efficient cryptography library for Android. (Auto fix SecureRandom bugs in API 18 and below.)

Features

  • AES-256 encryption algorithm
  • CBC/CTR mode of operations
  • Block padding with PKCS7 (only with CBC)
  • Computationally secure random salt (of cipher block size)
  • Password stretching with PBKDF2
  • Random IV generated on each encryption (16 bytes)
  • Supports MD5, SHA1, and SHA2 hash functions
  • Generate secure keys with SecureRandom or random.org
  • Asymmetric encryption with RSA
  • Auto handle large data by using hybrid asymmetric encryption
  • Supported RSA key sizes are 2048 bits and 4096 bits

This is an IntelliJ/Android Studio IDE plugin to detect the code with @Experimental and @Beta annotations and show a custom icon on the gutter when you use it.

Waterfall Toolbar is an Android version of Material Design's web component waterfall toolbar. Basically, what it does is dynamize an ordinary Toolbar, increasing and decreasing its shadow when an associated view is scrolled.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes