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

android {
    compileSdkVersion versions.compileSdk
    buildToolsVersion versions.buildTools

    defaultConfig {
        applicationId "chat.rocket.android"
        minSdkVersion 21
        targetSdkVersion versions.targetSdk
        versionCode 2008
        versionName "2.0.0-beta6"
        testInstrumentationRunner "android.support.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")
        }
    }

    buildTypes {
        release {
            buildConfigField "String", "REQUIRED_SERVER_VERSION", '"0.62.0"'
            buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.63.0"'
            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.63.0"'
            applicationIdSuffix ".dev"
        }
    }

    packagingOptions {
        exclude 'META-INF/core.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.design
    implementation libraries.constraintLayout
    implementation libraries.cardView
    implementation libraries.flexbox
    implementation libraries.customTabs

    implementation libraries.androidKtx

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

    implementation libraries.playServicesGcm

    implementation libraries.room
    kapt libraries.roomProcessor
    implementation libraries.roomRxjava

    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.markwonImageLoader

    implementation libraries.sheetMenu

    implementation libraries.aVLoadingIndicatorView

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

    testImplementation libraries.junit
    androidTestImplementation(libraries.expressoCore, {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}

kotlin {
    experimental {
        coroutines "enable"
    }
}

// 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'
