/*
 * Copyright (c) Ricki Hirner (bitfire web engineering).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 */

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

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "com.etesync.syncadapter"

        minSdkVersion 19
        targetSdkVersion 29

        versionCode 114
        versionName "1.16.2"

        buildConfigField "boolean", "customCerts", "true"
    }

    buildTypes {
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'

            /*
             * To override the server's url (for example when developing),
             * create file gradle.properties in ~/.gradle/ with this content:
             *
             * appDebugRemoteUrl="http://localserver:8080/"
             */
            if (project.hasProperty('appDebugRemoteUrl')) {
                buildConfigField 'String', 'DEBUG_REMOTE_URL', appDebugRemoteUrl
            } else {
                buildConfigField 'String', 'DEBUG_REMOTE_URL', 'null'
            }
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            buildConfigField 'String', 'DEBUG_REMOTE_URL', 'null'

            // Configure Kotlin compiler optimisations for releases
            kotlinOptions {
                freeCompilerArgs = [
                        '-Xno-param-assertions',
                        '-Xno-call-assertions',
                        '-Xno-receiver-assertions'
                ]
            }
        }
    }

    lintOptions {
        disable 'GoogleAppIndexingWarning'      // we don't need Google indexing, thanks
        disable 'GradleDependency'
        disable 'GradleDynamicVersion'
        disable 'IconColors'
        disable 'IconLauncherShape'
        disable 'IconMissingDensityFolder'
        disable 'ImpliedQuantity', 'MissingQuantity'
        disable 'MissingTranslation', 'ExtraTranslation'	// translations from Transifex are not always up to date
        disable 'Recycle'           // doesn't understand Lombok's @Cleanup
        disable 'RtlEnabled'
        disable 'RtlHardcoded'
        disable 'Typos'
        disable "RestrictedApi"		// https://code.google.com/p/android/issues/detail?id=230387
    }

    dexOptions {
        preDexLibraries = true
        // dexInProcess requires much RAM, which is not available on all dev systems
        dexInProcess = false
        javaMaxHeapSize "2g"
    }

    packagingOptions {
        exclude 'LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }

    defaultConfig {
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    /*
     * To sign release build, create file gradle.properties in ~/.gradle/ with this content:
     *
     * signingStoreLocation=/home/key.store
     * signingKeyAlias=alias
     *
     * and set the KSTOREPWD env var to the store and key passwords (should be the same)
     */
    if (project.hasProperty('signingStoreLocation') &&
            project.hasProperty('signingKeyAlias')) {
        println "Found sign properties in gradle.properties! Signing build…"

        signingConfigs {
            release {
                storeFile file(signingStoreLocation)
                storePassword System.getenv("KSTOREPWD")
                keyAlias signingKeyAlias
                keyPassword System.getenv("KSTOREPWD")
            }
        }
        buildTypes.release.signingConfig = signingConfigs.release
    } else {
        buildTypes.release.signingConfig = null
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dataBinding.enabled = true
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation "org.jetbrains.anko:anko-commons:0.10.4"

    implementation "com.etesync:journalmanager:1.1.1"

    def acraVersion = '5.3.0'
    implementation "ch.acra:acra-mail:$acraVersion"
    implementation "ch.acra:acra-notification:$acraVersion"
    def supportVersion = '1.0.0'
    implementation "androidx.legacy:legacy-support-core-ui:$supportVersion"
    implementation "androidx.core:core:$supportVersion"
    implementation "androidx.fragment:fragment:$supportVersion"
    implementation "androidx.appcompat:appcompat:1.1.0"
    implementation "androidx.cardview:cardview:1.0.0"
    implementation 'com.google.android.material:material:1.2.0-beta01'
    implementation "androidx.legacy:legacy-preference-v14:$supportVersion"
    implementation 'com.github.yukuku:ambilwarna:2.0.1'
    implementation ('com.github.worker8:tourguide:1.0.17-SNAPSHOT@aar') {
        transitive = true
    }

    def requeryVersion = '1.6.0'
    implementation "io.requery:requery:$requeryVersion"
    implementation "io.requery:requery-android:$requeryVersion"
    implementation "io.requery:requery-kotlin:$requeryVersion"
    kapt "io.requery:requery-processor:$requeryVersion"
    implementation 'com.google.code.findbugs:jsr305:3.0.2'

    def okhttp3Version = "4.8.1"
    implementation "com.squareup.okhttp3:okhttp:$okhttp3Version"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttp3Version"

    implementation 'com.google.code.gson:gson:1.7.2'
    implementation 'org.apache.commons:commons-collections4:4.1'
    implementation 'org.apache.commons:commons-lang3:3.8.1'

    implementation 'net.cachapa.expandablelayout:expandablelayout:2.9.2'
    implementation project(':cert4android')
    implementation project(':ical4android')
    implementation project(':vcard4android')
    // for tests
    androidTestImplementation('androidx.test:runner:1.1.0-alpha4') {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation('androidx.test:rules:1.1.0-alpha4') {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3Version"
    testImplementation 'junit:junit:4.12'
    testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp3Version"
}
