apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'com.github.triplet.play'
apply plugin: 'com.mikepenz.aboutlibraries.plugin'
apply from: 'jacoco.gradle'
apply from: 'sonarqube.gradle'
apply from: 'hooks.gradle'

android {
    compileSdkVersion 29
    buildToolsVersion '29.0.3'

    defaultConfig {
        applicationId "io.github.wulkanowy"
        testApplicationId "io.github.tests.wulkanowy"
        minSdkVersion 17
        targetSdkVersion 29
        versionCode 72
        versionName "0.21.2"
        multiDexEnabled true
        resValue "string", "app_name", "Wulkanowy"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        manifestPlaceholders = [
                firebase_enabled: project.hasProperty("enableFirebase")
        ]
        javaCompileOptions {
            annotationProcessorOptions {
                arguments += [
                        "room.schemaLocation": "$projectDir/schemas".toString(),
                        "room.incremental"   : "true"
                ]
            }
        }
    }

    sourceSets {
        androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
    }

    signingConfigs {
        release {
            storeFile file("upload-key.jks")
            storePassword System.getenv("PLAY_STORE_PASSWORD")
            keyAlias System.getenv("PLAY_KEY_ALIAS")
            keyPassword System.getenv("PLAY_KEY_PASSWORD")
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            resValue "string", "app_name", "Wulkanowy DEV " + defaultConfig.versionCode
            applicationIdSuffix ".dev"
            versionNameSuffix "-dev"
            testCoverageEnabled = project.hasProperty('coverage')
            ext.enableCrashlytics = project.hasProperty("enableFirebase")
        }
    }

    flavorDimensions "platform"

    productFlavors {
        play {
            dimension "platform"
        }

        fdroid {
            dimension "platform"
        }
    }

    buildFeatures {
        viewBinding = true
    }

    lintOptions {
        disable 'HardwareIds'
    }

    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
        freeCompilerArgs += ["-Xopt-in=kotlin.RequiresOptIn", "-Xjvm-default=all"]
    }

    packagingOptions {
        exclude 'META-INF/library_release.kotlin_module'
        exclude 'META-INF/library-core_release.kotlin_module'
    }

    aboutLibraries {
        configPath = "app/src/main/res/raw"
    }
}

play {
    serviceAccountEmail = System.getenv("PLAY_SERVICE_ACCOUNT_EMAIL") ?: "jan@fakelog.cf"
    serviceAccountCredentials = file('key.p12')
    defaultToAppBundles = false
    track = 'alpha'
}

ext {
    work_manager = "2.4.0"
    room = "2.2.5"
    chucker = "3.2.0"
    mockk = "1.10.0"
    moshi = "1.9.3"
}

configurations.all {
    resolutionStrategy.force "androidx.constraintlayout:constraintlayout:1.1.3"
}

dependencies {
    implementation "io.github.wulkanowy:sdk:0.21.2"

    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'

    implementation "androidx.core:core-ktx:1.3.1"
    implementation "androidx.activity:activity-ktx:1.1.0"
    implementation "androidx.appcompat:appcompat:1.2.0"
    implementation "androidx.appcompat:appcompat-resources:1.2.0"
    implementation "androidx.fragment:fragment-ktx:1.2.5"
    implementation "androidx.annotation:annotation:1.1.0"
    implementation "androidx.multidex:multidex:2.0.1"

    implementation "androidx.preference:preference-ktx:1.1.1"
    implementation "androidx.recyclerview:recyclerview:1.1.0"
    implementation "androidx.viewpager:viewpager:1.0.0"
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
    implementation "androidx.constraintlayout:constraintlayout:2.0.1"
    implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0"
    implementation "com.google.android.material:material:1.2.1"
    implementation "com.github.wulkanowy:material-chips-input:2.1.1"
    implementation "com.github.PhilJay:MPAndroidChart:v3.1.0"
    implementation "me.zhanghai.android.materialprogressbar:library:1.6.1"

    implementation "androidx.work:work-runtime-ktx:$work_manager"
    implementation "androidx.work:work-gcm:$work_manager"

    implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.2.0"

    implementation "androidx.room:room-runtime:$room"
    implementation "androidx.room:room-ktx:$room"
    kapt "androidx.room:room-compiler:$room"

    implementation "com.google.dagger:hilt-android:$hilt_version"
    kapt "com.google.dagger:hilt-android-compiler:$hilt_version"
    implementation 'androidx.hilt:hilt-work:1.0.0-alpha02'
    kapt 'androidx.hilt:hilt-compiler:1.0.0-alpha02'

    implementation "com.aurelhubert:ahbottomnavigation:2.3.4"
    implementation "com.ncapdevi:frag-nav:3.3.0"
    implementation "com.github.YarikSOffice:lingver:1.2.2"

    implementation "com.squareup.moshi:moshi:$moshi"
    implementation "com.squareup.moshi:moshi-adapters:$moshi"
    kapt "com.squareup.moshi:moshi-kotlin-codegen:$moshi"
    implementation "com.jakewharton.timber:timber:4.7.1"
    implementation "at.favre.lib:slf4j-timber:1.0.1"
    implementation "fr.bipi.treessence:treessence:0.3.2"
    implementation "com.mikepenz:aboutlibraries-core:$about_libraries"
    implementation 'com.wdullaer:materialdatetimepicker:4.2.3'
    implementation "io.coil-kt:coil:1.0.0-rc2"
    implementation "io.github.wulkanowy:AppKillerManager:3.0.0"
    implementation 'me.xdrop:fuzzywuzzy:1.3.1'

    playImplementation 'com.google.firebase:firebase-analytics:17.5.0'
    playImplementation 'com.google.firebase:firebase-inappmessaging-display-ktx:19.1.1'
    playImplementation "com.google.firebase:firebase-inappmessaging-ktx:19.1.1"
    playImplementation 'com.google.firebase:firebase-messaging:20.2.4'
    playImplementation 'com.google.firebase:firebase-crashlytics:17.2.1'
    playImplementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava'

    releaseImplementation "com.github.ChuckerTeam.Chucker:library-no-op:$chucker"

    debugImplementation "com.github.ChuckerTeam.Chucker:library:$chucker"
    debugImplementation "com.amitshekhar.android:debug-db:1.0.6"

    testImplementation "junit:junit:4.13"
    testImplementation "io.mockk:mockk:$mockk"
    testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.9'

    androidTestImplementation "androidx.test:core:1.3.0"
    androidTestImplementation "androidx.test:runner:1.3.0"
    androidTestImplementation "androidx.test.ext:junit:1.1.2"
    androidTestImplementation "io.mockk:mockk-android:$mockk"
    androidTestImplementation "androidx.room:room-testing:$room"
    androidTestImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}

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