Last active
August 29, 2015 14:12
-
-
Save alterakey/4b30e1962585c386694c to your computer and use it in GitHub Desktop.
AGP product flavor example (0.8)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:0.8.+' | |
} | |
} | |
apply plugin: 'android' | |
repositories { | |
maven { | |
url 'http://dl.bintray.com/populov/maven' | |
} | |
mavenCentral() | |
} | |
android { | |
final VERSION_NAME = "0.1.0" | |
final VERSION_CODE = 100 | |
compileSdkVersion 19 | |
buildToolsVersion '19.0.1' | |
defaultConfig { | |
minSdkVersion 14 | |
targetSdkVersion 19 | |
versionCode VERSION_CODE | |
versionName VERSION_NAME | |
packageName "package.name.for.release" | |
} | |
productFlavors { | |
dev { | |
versionName VERSION_NAME + "-" + getCheckedOutGitCommitHash() | |
} | |
stage { | |
versionName VERSION_NAME + "-" + getCheckedOutGitCommitHash() | |
packageName "package.name.for.stage" | |
} | |
prod { | |
} | |
} | |
compileOptions { | |
sourceCompatibility JavaVersion.VERSION_1_7 | |
targetCompatibility JavaVersion.VERSION_1_7 | |
} | |
signingConfigs { | |
release { | |
storeFile file('release.keystore') | |
storePassword System.getenv("PASSWORD") | |
keyAlias "release.key.alias" | |
keyPassword System.getenv("PASSWORD") | |
} | |
} | |
buildTypes { | |
release { | |
runProguard true | |
signingConfig signingConfigs.release | |
proguardFiles 'proguard-android-optimize.txt', 'proguard-rules.txt' | |
} | |
} | |
} | |
dependencies { | |
... | |
} | |
// https://gist.github.com/JonasGroeger/7620911 | |
def getCheckedOutGitCommitHash() { | |
def gitFolder = "$projectDir/../.git/" | |
def takeFromHash = 12 | |
/* | |
* '.git/HEAD' contains either | |
* in case of detached head: the currently checked out commit hash | |
* otherwise: a reference to a file containing the current commit hash | |
*/ | |
def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD | |
def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd | |
// def isRef = head.length > 1 // ref: refs/heads/master | |
if(isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb | |
def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master | |
refHead.text.trim().take takeFromHash | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment