Guest User

Untitled

a guest
May 21st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // VERSIONING - automatically infers version name and code based on the git tag which following //
  3. // the naming schema "release-v{major}.{minor}.{patch}" //
  4. // //
  5. // - Minor and Patch version should NOT exceed 99. //
  6. // - Maximum version code Google allow is 2100000000. This is equivalent to release-v210.0.0. //
  7. // //
  8. // Assuming your tag is: //
  9. // - release-v1.2.3 the code will be 10203000 //
  10. // - release-v11.22.33 the code will be 112233000 //
  11. // - release-v1.20.30 the code will be 12030000 //
  12. // - release-v1.99.99 the code will be 19999000 //
  13. // - release-v2.0.0 the code will be 20000000 //
  14. // - release-v209.99.99 the code will be 2099999000 //
  15. // //
  16. ////////////////////////////////////////////////////////////////////////////////////////////////////
  17.  
  18. def tag = "git describe --tags ${"git rev-list --tags --max-count=1".execute().text}".execute().text.trim()
  19. def name = tag.replace("release-v", "")
  20. def major = (name.substring(0, name.indexOf("."))).toInteger()
  21. def minor = (name.substring(name.indexOf(".") + 1, name.lastIndexOf("."))).toInteger()
  22. def patch = (name.substring(name.lastIndexOf(".") + 1, name.length())).toInteger()
  23. def code = major * 10000000 + minor * 100000 + patch * 1000
  24.  
  25. android { defaultConfig { versionCode code; versionName name } }
Add Comment
Please, Sign In to add comment