Skip to content

Instantly share code, notes, and snippets.

@murano500k
Created March 27, 2017 15:26
Show Gist options
  • Select an option

  • Save murano500k/10e937b3c8e29b3e583a23cd426c5c43 to your computer and use it in GitHub Desktop.

Select an option

Save murano500k/10e937b3c8e29b3e583a23cd426c5c43 to your computer and use it in GitHub Desktop.
Tips for build.gradle

//You can specify JVM arguments to Gradle daemon by entering a line in ~/.gradle/gradle.properties as shown below. org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 android.enableBuildCache=true android.builder.sdkDownload=true

######################################################################3 Use alfi to find the gradle dependency statement for a library

Its basically the command line version of Gradle, Please which is a web hosted. Run

alfi name_of_library

################################## Calculate the version code and version name in your build.gradle automatically, based on git information*

Note: These functions go specifically inside the app's build.gradle and cannot be used with ext. In your app's build.gradle

// Version code is calculated as the number of commits from last commit on master def getVersionCode = { -> try { def code = new ByteArrayOutputStream() exec { commandLine 'git', 'rev-list', 'HEAD', '--count' standardOutput = code } return Integer.parseInt(code.toString().trim()) } catch (exception) { return "1"; } }

// Version name is Last Tag Name + No. of commits form last Tag + short git sha def getVersionName = { -> try { def stdout = new ByteArrayOutputStream() exec { commandLine 'git', 'describe', '--tags', '--dirty' standardOutput = stdout } return stdout.toString().trim() } catch (exception) { return "0.0.0.1"; } }

// Use android{ defaultConfig { ... versionCode getVersionCode() versionName getVersionName() ... } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment