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.15.0"
    coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.1.5"

    implementation "androidx.appcompat:appcompat:1.7.0"
    implementation "androidx.work:work-runtime-ktx:2.10.0"
    implementation "androidx.activity:activity-ktx:1.10.1"

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

    // 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.12.0"
    implementation "androidx.compose.material3:material3:1.3.1"

    implementation "androidx.annotation:annotation:1.9.1"

    // 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.12.0"
    implementation "com.squareup.okhttp3:okhttp-dnsoverhttps:4.12.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.5"
    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.11.4"
    testImplementation "org.hamcrest:hamcrest-all:1.3"
    testImplementation "io.mockk:mockk:1.13.16"
    testImplementation "io.github.ivanshafran:shared-preferences-mock:1.2.4"
    testImplementation "org.slf4j:slf4j-simple:2.0.16"
}

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

    compileSdk 35

    defaultConfig {
        versionCode 178
        //  (incompatible changes) . (backwards compatible functionality) . (backwards compatible bug fixes)
        versionName "80.0.0"
        minSdk 21
        targetSdk 35
        vectorDrawables.useSupportLibrary = true
    }

    buildFeatures {
        viewBinding = true
        buildConfig = 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
    }

    // 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('printVersionNameAndVersion') {
    def versionNameAndCode = android.defaultConfig.versionName + "\n" + android.defaultConfig.versionCode.toString()
    doFirst {
        logger.error(versionNameAndCode)
    }
}
