apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion versions.compileSdk
    buildToolsVersion versions.buildTools

    defaultConfig {
        applicationId "chat.rocket.android"
        minSdkVersion 21
        targetSdkVersion versions.targetSdk
        versionCode 2030
        versionName "2.4.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    signingConfigs {
        release {
            storeFile project.rootProject.file('Rocket.jks').getCanonicalFile()
            storePassword System.getenv("KEYSTORE_PASSWORD")
            keyAlias System.getenv("KEY_ALIAS")
            keyPassword System.getenv("KEY_PASSWORD")
        }

        debug {
            storeFile project.rootProject.file('debug.keystore').getCanonicalFile()
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
    }

    buildTypes {
        release {
            buildConfigField "String", "REQUIRED_SERVER_VERSION", '"0.62.0"'
            buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.64.2"'
            signingConfig signingConfigs.release
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        debug {
            buildConfigField "String", "REQUIRED_SERVER_VERSION", '"0.62.0"'
            buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.64.2"'
            signingConfig signingConfigs.debug
            applicationIdSuffix ".dev"
        }
    }

    packagingOptions {
        exclude 'META-INF/core.kotlin_module'
        exclude 'META-INF/main.kotlin_module'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation project(':player')

    implementation libraries.kotlin
    implementation libraries.coroutines
    implementation libraries.coroutinesAndroid

    implementation libraries.appCompat
    implementation libraries.recyclerview
    implementation libraries.material
    implementation libraries.constraintlayout
    implementation libraries.cardview
    implementation libraries.flexbox
    implementation libraries.browser

    implementation libraries.androidKtx

    implementation libraries.dagger
    implementation libraries.daggerSupport
    kapt libraries.daggerProcessor
    kapt libraries.daggerAndroidApt

    implementation libraries.fcm
    implementation libraries.playServicesAuth

    implementation libraries.room
    kapt libraries.roomProcessor
    implementation libraries.lifecycleExtensions
    kapt libraries.lifecycleCompiler

    implementation libraries.rxKotlin
    implementation libraries.rxAndroid

    implementation libraries.moshi
    implementation libraries.okhttp
    implementation libraries.okhttpLogger

    implementation libraries.timber
    implementation libraries.threeTenABP
    implementation libraries.rxBinding

    implementation libraries.fresco
    api libraries.frescoOkHttp
    implementation libraries.frescoAnimatedGif
    implementation libraries.frescoWebP
    implementation libraries.frescoAnimatedWebP

    kapt libraries.kotshiCompiler
    implementation libraries.kotshiApi

    implementation libraries.frescoImageViewer

    implementation libraries.markwon

    implementation libraries.sheetMenu

    implementation libraries.aVLoadingIndicatorView

    implementation "com.github.luciofm:livedata-ktx:b1e8bbc25a"

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

    testImplementation libraries.junit
    testImplementation libraries.truth
    androidTestImplementation libraries.espressoCore
    androidTestImplementation libraries.espressoIntents
}

kotlin {
    experimental {
        coroutines "enable"
    }
}

androidExtensions {
    experimental = true
}

// FIXME - build and install the sdk into the app/libs directory
// We were having some issues with the kapt generated files from the sdk when importing as a module
task compileSdk(type:Exec) {
    if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
        commandLine 'cmd', '/c', 'build-sdk.sh'
    } else {
        commandLine './build-sdk.sh'
    }
}
preBuild.dependsOn compileSdk

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