Skip to content

Instantly share code, notes, and snippets.

@marsicdev
Created May 4, 2017 14:08
Show Gist options
  • Save marsicdev/4dc4264cb0e0531a7c1f58321d99485c to your computer and use it in GitHub Desktop.
Save marsicdev/4dc4264cb0e0531a7c1f58321d99485c to your computer and use it in GitHub Desktop.
Starter Android app gradle files (kotlin)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
def BOOLEAN = "boolean"
def STRING = "String"
def TRUE = "true"
def FALSE = "false"
def LOG_HTTP_REQUESTS = "LOG_HTTP_REQUESTS"
def REPORT_CRASHES = "REPORT_CRASHES"
def API_URL = "API_URL"
def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 1
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "info.marsic.APP_NAME"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch * 10 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFiles fileTree(include: ['*.pro'], dir: 'proguard').asList().toArray()
vectorDrawables {
useSupportLibrary = true
}
buildConfigField STRING, API_URL, '"http://API_URL/"'
buildConfigField BOOLEAN, LOG_HTTP_REQUESTS, TRUE
buildConfigField BOOLEAN, REPORT_CRASHES, FALSE
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
debug {
storeFile file(DEBUG_KEYSTORE_PATH)
storePassword DEBUG_KEYSTORE_PASS
keyAlias DEBUG_KEY_ALIAS
keyPassword DEBUG_KEY_PASS
}
release {
storeFile file(RELEASE_KEYSTORE_PATH)
storePassword RELEASE_KEYSTORE_PASS
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASS
}
}
buildTypes {
debug {
applicationIdSuffix ".debug"
versionNameSuffix "-debug"
debuggable true
minifyEnabled false
shrinkResources false
testCoverageEnabled = TRUE
signingConfig signingConfigs.debug
}
release {
debuggable false
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.release
}
}
sourceSets {
debug.java.srcDirs += 'src/debug/kotlin'
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
androidTest.java.srcDirs += 'src/androidTest/kotlin'
}
// Always show the result of every unit test, even if it passes.
testOptions.unitTests.all {
testLogging {
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
outputs.upToDateWhen { false }
showStandardStreams = true
}
}
lintOptions {
checkReleaseBuilds true
abortOnError true
disable 'InvalidPackage'
}
}
tasks.whenTaskAdded { task ->
if (task.name == "lint") {
task.enabled = false
}
}
dependencies {
compile(
fileTree(include: ['*.jar'], dir: 'libs'),
"com.android.support:support-v4:${supportLibVersion}",
"com.android.support:appcompat-v7:${supportLibVersion}",
"com.android.support:recyclerview-v7:${supportLibVersion}",
"com.android.support:cardview-v7:${supportLibVersion}",
"com.android.support:design:${supportLibVersion}",
"com.android.support.constraint:constraint-layout:${constraintLayoutVersion}",
// Kotlin
"org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}",
// RxJava
"io.reactivex.rxjava2:rxjava:${rxJavaVersion}",
"io.reactivex.rxjava2:rxandroid:${rxAndroidVersion}",
// Dagger
"com.google.dagger:dagger:${daggerVersion}",
// rest client for http interaction and dependencies
"com.squareup.retrofit2:retrofit:${retrofitVersion}",
"com.squareup.retrofit2:converter-gson:${retrofitVersion}",
"com.squareup.retrofit2:adapter-rxjava2:${retrofitVersion}",
"com.squareup.okhttp3:okhttp:${okhttpVersion}",
"com.squareup.okhttp3:logging-interceptor:${okhttpVersion}"
)
kapt(
"com.google.dagger:dagger-compiler:${daggerVersion}"
)
testCompile(
"org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}",
"org.jetbrains.kotlin:kotlin-test-junit:${kotlinVersion}",
// Unit testing dependencies
"junit:junit:${junitVersion}",
"org.mockito:mockito-core:${mockitoVersion}",
"org.hamcrest:hamcrest-library:${hamcrestVersion}"
)
testCompile("com.squareup.assertj:assertj-android:${assertjVersion}") {
exclude module: "support-annotations"
}
kaptAndroidTest "com.google.dagger:dagger-compiler:${daggerVersion}"
androidTestCompile(
"com.android.support:support-annotations:${supportLibVersion}",
"com.android.support.test:runner:${runnerVersion}",
// Set this dependency to use JUnit 4 rules
"com.android.support.test:rules:${rulesVersion}",
// Set this dependency to build and run UI Automator tests
"org.mockito:mockito-core:${mockitoVersion}",
// Set this dependency to build and run Espresso tests
"com.android.support.test.espresso:espresso-core:${espressoVersion}",
"com.crittercism.dexmaker:dexmaker:${dexMakerVersion}",
"com.crittercism.dexmaker:dexmaker-mockito:${dexMakerVersion}",
"com.crittercism.dexmaker:dexmaker-dx:${dexMakerVersion}"
)
androidTestCompile("com.android.support.test.espresso:espresso-contrib:${espressoVersion}") {
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlinVersion = '1.1.2-3'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.4.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:${kotlinVersion}"
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
compileSdkVersion = 25
buildToolsVersion = '25.0.2'
devMinSdkVersion = 24
minSdkVersion = 16
targetSdkVersion = 25
supportLibVersion = '25.2.0'
constraintLayoutVersion = '1.0.2'
// Third party libs
butterknifeVersion = '8.5.1'
okhttpVersion = '3.6.0'
retrofitVersion = '2.2.0'
daggerVersion = '2.9'
rxJavaVersion = '2.0.6'
rxAndroidVersion = '2.0.1'
// Test libs
mockitoVersion = '2.0.2-beta'
hamcrestVersion = '1.3'
assertjVersion = '1.1.1'
junitVersion = '4.12'
runnerVersion = '0.4.1'
uiautomatorVersion = '2.1.2'
rulesVersion = '0.4.1'
espressoVersion = '2.2.1'
dexMakerVersion = '1.4'
}
// Since there will not be any incremental builds,
// it is really not needed to use pre-dexing.
// Disable it only on build server
project.ext.preDexLibs = !project.hasProperty('disablePreDex')
subprojects {
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin" == plugin.class.name) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
} else if ("com.android.build.gradle.LibraryPlugin" == plugin.class.name) {
project.android.dexOptions.preDexLibraries = rootProject.ext.preDexLibs
}
}
}
# Gradle config
org.gradle.jvmargs=-Xmx2048M
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
# Project-wide Gradle settings.
DEBUG_KEYSTORE_PATH=../keys/my-debug-key.jks
DEBUG_KEYSTORE_PASS=SECRET_KEYSTORE_PASSWORD
DEBUG_KEY_ALIAS=MY_DEBUG_APP_ALIAS
DEBUG_KEY_PASS=SECRET_ALIAS_PASSWORD
RELEASE_KEYSTORE_PATH=../keys/my-release-key.jks
RELEASE_KEYSTORE_PASS=SECRET_KEYSTORE_PASSWORD
RELEASE_KEY_ALIAS=MY_RELEASE_APP_ALIAS
RELEASE_KEY_PASS=SECRET_ALIAS_PASSWORD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment