Skip to content

Instantly share code, notes, and snippets.

@muratcanbur
Created July 6, 2015 20:53
Show Gist options
  • Save muratcanbur/1c54b5d7ec58c92c4854 to your computer and use it in GitHub Desktop.
Save muratcanbur/1c54b5d7ec58c92c4854 to your computer and use it in GitHub Desktop.
this is a Gradle guide to use on all Android applications in general.
apply plugin: 'com.android.application'
Properties local_properties = new Properties()
File localPropertiesFile = project.rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
local_properties.load(localPropertiesFile.newDataInputStream())
}
def STRING = 'String'
def GIT_SHA = 'GIT_SHA'
def BUILD_TIME = 'BUILD_TIME'
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
def buildTime = new Date().format("yyyy-MM-dd'T'HH:mm'Z'", TimeZone.getTimeZone("UTC"))
android {
publishNonDefault true
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "co.mobiwise.project_name"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode rootProject.ext.versionMajor * 10000 + rootProject.ext.versionMinor * 1000 + rootProject.ext.versionPatch * 100 + rootProject.ext.versionBuild
versionName "${rootProject.ext.versionMajor}.${rootProject.ext.versionMinor}" + ((rootProject.ext.versionPatch != 0) ? ".${rootProject.ext.versionPatch}" : "")
buildConfigField STRING, GIT_SHA, "\"${gitSha}\""
buildConfigField STRING, BUILD_TIME, "\"${buildTime}\""
buildConfigField INT, DATABASE_VERSION, '1'
buildConfigField INT, CONNECTION_TIMEOUT, '2000'
buildConfigField BOOLEAN, IS_DOGFOOD_BUILD, FALSE
}
signingConfigs {
debug {
storeFile file("../distribution/debug.keystore")
}
release {
storeFile file("../distribution/" + (local_properties.release_keystore_name ?: "debug.keystore"))
keyAlias(local_properties.release_keystore_alias ?: "androiddebugkey")
storePassword(local_properties.release_keystore_pwd ?: "android")
keyPassword(local_properties.release_keystore_pwd2 ?: "android")
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
buildConfigField BOOLEAN, IS_DOGFOOD_BUILD, TRUE
buildConfigField STRING, LOG_PREFIX, '"co.mobiwise.project_name"'
buildConfigField INT, CONNECTION_TIMEOUT, '5000'
buildConfigField STRING, DATABASE_NAME, '"debug_tcm_sfa.sqlite"'
minifyEnabled false
}
release {
buildConfigField STRING, LOG_PREFIX, '"co.mobiwise.project_name"'
buildConfigField STRING, DATABASE_NAME, '"co.mobiwise.project_name.sqlite"'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup:otto:1.3.8'
compile 'com.android.support:design:22.2.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:cardview-v7:22.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.j256.ormlite:ormlite-android:4.48'
}
buildscript {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0-beta3'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3'
}
}
apply plugin: 'com.github.ben-manes.versions'
allprojects {
repositories {
jcenter()
mavenCentral()
mavenLocal()
}
}
ext {
preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
versionMajor = 1
versionMinor = 0
versionPatch = 0
versionBuild = 0
compileSdkVersion = 22
buildToolsVersion = "22.2.0"
targetSdkVersion = 22
minSdkVersion = 9
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment