plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'de.mannodermaus.android-junit5'
    id 'kotlin-parcelize'
    id 'org.jetbrains.kotlin.android'
    id 'dev.rikka.tools.refine'
}

dependencies {
    implementation 'androidx.core:core-ktx:1.12.0'
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'

    implementation 'androidx.appcompat:appcompat:1.6.1'

    implementation 'androidx.core:core-ktx:1.12.0'
    implementation 'androidx.work:work-runtime-ktx:2.8.1'

    // solve dependency conflict https://stackoverflow.com/a/69832319
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'

    // has kotlinx-coroutines-android
    implementation 'androidx.preference:preference-ktx:1.2.1'

    // has coordinatorlayout, constraintlayout, cardview and more
    implementation 'com.google.android.material:material:1.10.0'
    implementation "androidx.compose.material3:material3:1.1.2"

    implementation 'androidx.annotation:annotation:1.7.0'

    // additional layout for then main screen
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

    // parse API responses in JSON
    implementation 'com.google.code.gson:gson:2.10.1'

    // compare versions of available and installed apps
    implementation 'io.github.g00fy2:versioncompare:1.5.0'

    // for file downloader
    implementation 'com.squareup.okhttp3:okhttp:4.11.0'
    implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.11.0'

    implementation 'ru.gildor.coroutines:kotlin-coroutines-okhttp:1.0'

    // for root installer
    implementation 'com.github.topjohnwu.libsu:core:5.2.0'

    // for Shizuku installer
    compileOnly "dev.rikka.hidden:stub:4.2.0"
    implementation "dev.rikka.tools.refine:runtime:4.3.0"
    def shizuku_version = '13.1.2'
    implementation "dev.rikka.shizuku:api:${shizuku_version}"
    implementation "dev.rikka.shizuku:provider:${shizuku_version}"
    implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:4.3'

    // Aggregator dependency on JUnit api, engine, and params
    testImplementation 'org.junit.jupiter:junit-jupiter:5.9.3'
    testImplementation 'org.hamcrest:hamcrest-all:1.3'
    testImplementation 'io.mockk:mockk:1.13.5'
    testImplementation 'io.github.ivanshafran:shared-preferences-mock:1.2.4'
    testImplementation 'org.slf4j:slf4j-simple:2.0.9'
}

android {
    namespace = 'de.marmaro.krt.ffupdater'

    compileSdk 34

    defaultConfig {
        versionCode 168
        //  (incompatible changes) . (backwards compatible functionality) . (backwards compatible bug fixes)
        versionName '79.1.0'
        minSdk 21
        targetSdk 34
        vectorDrawables.useSupportLibrary = true
    }

    buildFeatures {
        viewBinding = true
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        encoding = "UTF-8"
        coreLibraryDesugaringEnabled true
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    packagingOptions {
        resources {
            excludes += ['META-INF/NOTICE', 'META-INF/NOTICE.txt', 'META-INF/README', 'META-INF/README.txt',
                         'META-INF/LICENSE', 'META-INF/LICENSE.txt']
        }
    }

    testOptions {
        // workaround for "Method i in android.util.Log not mocked"
        // without PowerMockito it is impossible to mock Log.
        unitTests.returnDefaultValues = true
        unitTests.includeAndroidResources = true
        unitTests.all {
            maxParallelForks = Runtime.runtime.availableProcessors()
            testLogging {
                events "passed", "skipped", "failed", "standardOut", "standardError"
                outputs.upToDateWhen { false }
                showStandardStreams = true
            }
        }
    }

    lint {
        abortOnError false
    }
    androidResources {
        additionalParameters '--warn-manifest-validation'
    }

    // remove the Dependency Info Block
    // https://gitlab.com/fdroid/fdroiddata/-/merge_requests/13812#note_1592074265
    dependenciesInfo {
        // Disables dependency metadata when building APKs.
        includeInApk = false
        // Disables dependency metadata when building Android App Bundles.
        includeInBundle = false
    }
}

tasks.register('printVersionName') {
    doLast {
        println android.defaultConfig.versionName
    }
}

tasks.register('printVersionCode') {
    doLast {
        println android.defaultConfig.versionCode
    }
}