def getGitSha() {
    return 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
}

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        maven { url 'https://maven.google.com' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.28.0'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://dl.bintray.com/hani-momanii/maven" }
    maven { url "https://jitpack.io" }
}

apply plugin: 'realm-android'

android {
    compileSdkVersion 27
    buildToolsVersion '28.0.2'

    defaultConfig {
        applicationId "de.beyondsoft.ownchat"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 26
        versionName "1.26"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    signingConfigs {
        release {
            storeFile file('../ownChat.jks')
            storePassword 'jlzvnz9e4ur3gfk6hwsw'
            keyAlias 'ownChatKey'
            keyPassword '6fhnfqm07tvbagm3t6k4'
        }
    }

    buildTypes {
        debug {
            ext.enableCrashlytics = false
            minifyEnabled = false
        }

        release {
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField "String", "GIT_VERSION_SHA", "\"" + getGitSha() + "\""
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {
        abortOnError false
        disable 'InvalidPackage'
    }

    dexOptions {
        javaMaxHeapSize "12g"
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    implementation 'com.android.support:multidex:1.0.3'


    implementation('com.github.bumptech.glide:glide:4.7.1') {
        exclude group: 'com.android.support'
    }

    implementation('com.crashlytics.sdk.android:crashlytics:2.10.1@aar') {
        transitive = true
    }

    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.jakewharton:butterknife:8.8.1'
    implementation 'com.google.dagger:dagger:2.7'
    implementation 'io.reactivex:rxjava:1.1.6'
    implementation 'io.reactivex:rxandroid:1.2.1'
    implementation 'com.jakewharton.rxbinding:rxbinding:0.4.0'
    implementation 'com.squareup.retrofit2:retrofit:2.2.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'

    implementation 'de.hdodenhof:circleimageview:2.1.0'
    implementation 'com.scottyab:secure-preferences-lib:0.1.4'
    implementation 'com.google.firebase:firebase-messaging:17.3.3'
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'hani.momanii.supernova_emoji_library:supernova-emoji-library:0.0.2'
    implementation 'com.github.lzyzsd:circleprogress:1.2.1'
    implementation 'org.greenrobot:eventbus:3.0.0'
    testImplementation 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.7'
    compileOnly 'javax.annotation:jsr250-api:1.0'
    implementation files('libs/sanselan-0_97-android-1.0.0.jar')
    implementation 'com.firebase:firebase-jobdispatcher:0.5.2'
    implementation 'com.google.android.gms:play-services-base:16.0.1'
    implementation files('libs/core-1.58.0.0.jar')
    implementation files('libs/prov-1.58.0.0.jar')
    implementation files('libs/bcpkix-jdk15on-1.58.0.0.jar')
    implementation files('libs/bcpg-jdk15on-1.58.0.0.jar')
}

task adp2upload(type: Exec, dependsOn: "build") {
    ext {
        channel = "bewoplaner-chat"
        slug = "bewoplaner-chat"
        versionCode = rootProject.versionCode
        identifier = "de.p3.bewoplaner"
        file = "build/outputs/apk/app-release.apk"
        notes = "Nightly build for BeWoPlaner Chat"
    }

    commandLine 'upload_build.sh', "-c", "$channel", "-v", "$versionCode", "-p", "android", "-a", "$slug", "-f", "$file", "-i", "$identifier", "-n", "$notes"
}

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