daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 50 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. # First create the file version.properties with value VERSION_BUILD=0
  2. # In app/build.gradle:
  3.  
  4. android {
  5.     def versionPropsFile = file('version.properties')
  6.     def versionBuild
  7.  
  8.     if (versionPropsFile.canRead()) {
  9.         def Properties versionProps = new Properties()
  10.         versionProps.load(new FileInputStream(versionPropsFile))
  11.         versionBuild = versionProps['VERSION_BUILD'].toInteger()
  12.     } else {
  13.         throw new FileNotFoundException("Could not read version.properties!")
  14.     }
  15.  
  16.     ext.autoIncrementBuildNumber = {
  17.         if (versionPropsFile.canRead()) {
  18.             def Properties versionProps = new Properties()
  19.             versionProps.load(new FileInputStream(versionPropsFile))
  20.             versionBuild = versionProps['VERSION_BUILD'].toInteger() + 1
  21.             versionProps['VERSION_BUILD'] = versionBuild.toString()
  22.             versionProps.store(versionPropsFile.newWriter(), null)
  23.         } else {
  24.             throw new FileNotFoundException("Could not read version.properties!")
  25.         }
  26.     }
  27.    
  28.     # Add / change this part in defaultConfig for the versionCode
  29.     defaultConfig {
  30.         versionCode versionBuild
  31.     }
  32.    
  33.     gradle.taskGraph.whenReady { taskGraph ->
  34.         if (taskGraph.hasTask(assembleDebug)) {
  35.             autoIncrementBuildNumber()
  36.         } else if (taskGraph.hasTask(assembleRelease)) {
  37.             autoIncrementBuildNumber()
  38.         }
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top