Created
March 20, 2015 10:21
-
-
Save akalongman/de76ad46d8d510e71823 to your computer and use it in GitHub Desktop.
Android build.gradle example
This file contains 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
apply plugin: 'com.android.application' | |
def getBuildDate() { | |
def date = new Date() | |
def formattedDate = date.format("yyyy-MM-dd'T'HH:mm:ss'Z'") | |
return formattedDate | |
} | |
def BUILD_DATE = getBuildDate() | |
android { | |
compileSdkVersion 22 | |
buildToolsVersion "21.1.2" | |
def Properties versionProps = new Properties() | |
versionProps.load(new FileInputStream(file('version.properties'))) | |
defaultConfig { | |
applicationId "ge.itdc.apps.freshnews" | |
minSdkVersion 15 | |
targetSdkVersion 22 | |
versionName versionProps['name'] | |
versionCode versionProps['code'].toInteger() | |
} | |
signingConfigs { | |
debug { | |
storeFile file("config/debug.keystore") | |
} | |
release { | |
storeFile file("config/debug.keystore") | |
storePassword "android" | |
keyAlias "android" | |
keyPassword "android" | |
} | |
} | |
if (project.rootProject.file('local.properties').exists()) { | |
def propFile = new File('local.properties') | |
if (propFile.canRead()) { | |
def Properties props = new Properties() | |
props.load(new FileInputStream(propFile)) | |
if (props.getProperty('MyProject.keystore')) { | |
println("DBG: File local.properties hasProperty MyProject.keystore") | |
signingConfigs { | |
debug { | |
storeFile signingConfigs.debug.storeFile | |
} | |
release { | |
storeFile file(props.getProperty('MyProject.keystore')) | |
storePassword props.getProperty('MyProject.keystore.password') | |
keyAlias props.getProperty('MyProject.keyAlias') | |
keyPassword props.getProperty('MyProject.keyPassword') | |
} | |
} | |
} else { | |
println("MyProject.keystore property not found in file local.properties") | |
} | |
} | |
} | |
buildTypes { | |
debug { | |
applicationIdSuffix ".debug" | |
versionNameSuffix "-debug" + " build-" + BUILD_DATE | |
signingConfig signingConfigs.debug | |
debuggable true | |
zipAlignEnabled false | |
minifyEnabled false | |
} | |
release { | |
versionNameSuffix " build-" + BUILD_DATE | |
signingConfig signingConfigs.release | |
debuggable false | |
zipAlignEnabled true | |
minifyEnabled true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
} | |
} | |
sourceSets { | |
debug { | |
java.srcDirs = ['src/debug/java', 'src/debug/java/'] | |
//manifest.srcFile 'config/debug/AndroidManifest.xml' | |
} | |
release { | |
java.srcDirs = ['src/release/java', 'src/release/java/'] | |
//manifest.srcFile 'config/release/AndroidManifest.xml' | |
} | |
} | |
} | |
/* | |
android.applicationVariants.all { variant -> | |
variant.assemble << { | |
def versionName = android.defaultConfig.versionName | |
def versionNameSuffix = variant.buildType.versionNameSuffix ?: '' | |
copy { | |
from variant.outputFile | |
into variant.outputFile.parent | |
rename { String filename -> | |
filename.replace('.apk', sprintf('-v%s%s.apk', versionName, versionNameSuffix)) | |
} | |
} | |
} | |
} | |
*/ | |
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
compile 'com.google.android.gms:play-services:7.0.0' // 3.1.+ | |
compile 'com.mcxiaoke.volley:library:1.0.15' | |
compile 'com.android.support:support-v4:22.0.0' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you,
apply plugin: 'com.android.application'
was the key for me!