apply plugin: 'com.android.application'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion as int
    buildToolsVersion rootProject.ext.buildToolsVersion as String

    compileOptions {
        sourceCompatibility rootProject.ext.javaVersion as JavaVersion
        targetCompatibility rootProject.ext.javaVersion as JavaVersion
    }

    defaultConfig {
        applicationId "com.vanniktech.vntfontlistpreference.sample"
        minSdkVersion rootProject.ext.minSdkVersion as int
        targetSdkVersion rootProject.ext.targetSdkVersion as int
        versionCode rootProject.ext.versionCode as int
        versionName rootProject.ext.versionName as String
    }

    def shouldSign = project.hasProperty('RELEASE_STORE_FILE') && project.hasProperty('RELEASE_STORE_PASSWORD') && project.hasProperty('RELEASE_KEY_ALIAS') && project.hasProperty('RELEASE_KEY_PASSWORD')

    if (shouldSign) {
        signingConfigs {
            release {
                // http://stackoverflow.com/a/21020469/1979703
                storeFile file(RELEASE_STORE_FILE)
                storePassword RELEASE_STORE_PASSWORD
                keyAlias RELEASE_KEY_ALIAS
                keyPassword RELEASE_KEY_PASSWORD
            }
        }
    }

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.outputFile = new File(output.outputFile.parent, output.outputFile.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            shrinkResources true
            zipAlignEnabled true

            if (shouldSign) {
                signingConfig signingConfigs.release
            }
        }

        debug {
            versionNameSuffix '-RC'
        }
    }
}

dependencies {
    compile project(':library')

    compile rootProject.ext.supportAppCompat

    debugCompile rootProject.ext.leakCanaryDebug
    releaseCompile rootProject.ext.leakCanaryRelease
}