apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'kotlin-kapt'

if (rootProject.testCoverage) {
    apply plugin: 'jacoco'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"

    implementation project(":app:ui:legacy")
    implementation project(":app:core")
    implementation project(":app:storage")
    implementation project(":app:crypto-openpgp")
    implementation project(":backend:imap")
    implementation project(":backend:pop3")
    implementation project(":backend:webdav")
    implementation project(":backend:jmap")

    implementation "androidx.appcompat:appcompat:${versions.androidxAppCompat}"
    implementation "com.jakewharton.timber:timber:${versions.timber}"
    implementation "androidx.constraintlayout:constraintlayout:${versions.androidxConstraintLayout}"
    implementation "com.google.android.material:material:${versions.materialComponents}"
    implementation "androidx.navigation:navigation-fragment-ktx:${versions.androidxNavigation}"
    implementation "androidx.navigation:navigation-ui-ktx:${versions.androidxNavigation}"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${versions.androidxLifecycle}"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:${versions.androidxLifecycle}"

    implementation "com.github.bumptech.glide:glide:${versions.glide}"
    kapt "com.github.bumptech.glide:compiler:${versions.glide}"

    // Required for DependencyInjectionTest to be able to resolve OpenPgpApiManager
    testImplementation project(':plugins:openpgp-api-lib:openpgp-api')

    testImplementation "org.robolectric:robolectric:${versions.robolectric}"
    testImplementation "junit:junit:${versions.junit}"
    testImplementation "com.google.truth:truth:${versions.truth}"
    testImplementation "org.mockito:mockito-core:${versions.mockito}"
    testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${versions.mockitoKotlin}"
    testImplementation "org.koin:koin-test:${versions.koin}"
}

android {
    compileSdkVersion buildConfig.compileSdk
    buildToolsVersion buildConfig.buildTools

    defaultConfig {
        applicationId "com.fsck.k9.jmap"
        testApplicationId "com.fsck.k9.jmap.tests"

        versionCode 1
        versionName 'JMAP DEV'

        minSdkVersion buildConfig.minSdk
        targetSdkVersion buildConfig.targetSdk

        generatedDensities = ['mdpi', 'hdpi', 'xhdpi']

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release
    }

    buildTypes {
        release {
            if (project.hasProperty('storeFile')) {
                signingConfig signingConfigs.release
            }

            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            buildConfigField "boolean", "DEVELOPER_MODE", "false"
        }

        debug {
            applicationIdSuffix ".debug"
            testCoverageEnabled rootProject.testCoverage

            minifyEnabled false

            buildConfigField "boolean", "DEVELOPER_MODE", "true"
        }
    }

    // Do not abort build if lint finds errors
    lintOptions {
        abortOnError false
        lintConfig file("$rootProject.projectDir/config/lint/lint.xml")
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/README'
        exclude 'LICENSE.txt'
        exclude 'META-INF/*.kotlin_module'
    }

    compileOptions {
        sourceCompatibility javaVersion
        targetCompatibility javaVersion
    }

    kotlinOptions {
        jvmTarget = kotlinJvmVersion
    }

    buildFeatures {
        dataBinding = true
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}

if (project.hasProperty('keyAlias')) {
    android.signingConfigs.release.keyAlias = keyAlias
}
if (project.hasProperty('keyPassword')) {
    android.signingConfigs.release.keyPassword = keyPassword
}
if (project.hasProperty('storeFile')) {
    android.signingConfigs.release.storeFile = file(storeFile)
}
if (project.hasProperty('storePassword')) {
    android.signingConfigs.release.storePassword = storePassword
}
