apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    def versionPropsFile = file('version.properties')

    /*
    Version numbering from: http://andreborud.com/android-studio-automatic-incremental-gradle-versioning/
     */
    if (versionPropsFile.canRead()) {
        def Properties versionProps = new Properties()

        versionProps.load(new FileInputStream(versionPropsFile))
        def value = 0
        def runTasks = gradle.startParameter.taskNames
        if ('assemble' in runTasks || 'assembleRelease' in runTasks || 'aR' in runTasks || 'generateReleaseBuildConfig' in runTasks) {
            value = 1;
        }

        def versionMajor = 1
        def versionMinor = 5
        def versionPatch = versionProps['VERSION_PATCH'].toInteger() + value
        def versionBuild = versionProps['VERSION_BUILD'].toInteger() + 1
        def version_Code = versionProps['VERSION_CODE'].toInteger() + value

        versionProps['VERSION_PATCH'] = versionPatch.toString()
        versionProps['VERSION_BUILD'] = versionBuild.toString()
        versionProps['VERSION_CODE'] = version_Code.toString()

        versionProps.store(versionPropsFile.newWriter(), null)

        defaultConfig {
            applicationId "com.elixsr.portforwarder"
            minSdkVersion 16
            targetSdkVersion 25
            versionCode version_Code
            versionName "${versionMajor}.${versionMinor}.${versionPatch} (${versionBuild})"
            multiDexEnabled true
        }
    } else {
        throw new GradleException("Could not read version.properties!")
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    /* Followed: https://github.com/androidannotations/androidannotations/issues/1951 */
    dexOptions {
        preDexLibraries = false
    }
    productFlavors {
    }
}

def playServicesVersion = '15.0.0'
def firebaseVersion = '15.0.0'
def supportLibraryVersion = '27.1.1'

dependencies {
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$supportLibraryVersion"
    implementation "com.android.support:customtabs:$supportLibraryVersion"
    implementation "com.android.support:design:$supportLibraryVersion"
    implementation "com.android.support:percent:$supportLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
    implementation 'com.elixsr:elixsr-core:0.1.8'
    implementation 'com.github.paolorotolo:appintro:4.0.0'
    implementation "com.google.android.gms:play-services-analytics:$playServicesVersion"
    implementation "com.google.android.gms:play-services-ads:$playServicesVersion"
    implementation "com.google.android.gms:play-services-auth:$playServicesVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    implementation "com.google.firebase:firebase-core:$firebaseVersion"
    implementation "com.google.firebase:firebase-crash:$firebaseVersion"
    implementation "com.google.firebase:firebase-auth:$firebaseVersion"
    implementation "com.google.firebase:firebase-ads:$firebaseVersion"
    implementation "com.google.firebase:firebase-database:$firebaseVersion"
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.2'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'