apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'de.mannodermaus.android-junit5'
apply plugin: 'org.owasp.dependencycheck'
apply plugin: 'kotlin-parcelize'

repositories {
    mavenCentral()
    google()
    maven {
        url 'https://jitpack.io'
        content {
            includeModule('com.github.topjohnwu.libsu', 'core')
        }
    }
}

dependencies {
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.2'

    implementation 'androidx.appcompat:appcompat:1.6.0'

    implementation 'androidx.core:core-ktx:1.9.0'
    implementation 'androidx.work:work-runtime-ktx:2.7.1'

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

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

    // has coordinatorlayout, constraintlayout, cardview and more
    implementation 'com.google.android.material:material:1.8.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.9.0'

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

    // for file downloader
    //noinspection GradleDependency
    implementation 'com.squareup.okhttp3:okhttp:4.10.0'
    implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps:4.10.0'

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

    // for root installer
    // TODO
    //noinspection GradleDependency
    implementation 'com.github.topjohnwu.libsu:core:5.0.4'

    // for Shizuku installer
    implementation "dev.rikka.shizuku:api:12.2.0"
    implementation "dev.rikka.shizuku:provider:12.2.0"

    // Aggregator dependency on JUnit api, engine, and params
    testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
    testImplementation 'io.mockk:mockk:1.10.5'
    //noinspection GradleDependency
    testImplementation 'io.github.ivanshafran:shared-preferences-mock:1.2.4'
}

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

    compileSdkVersion 33

    defaultConfig {
        versionCode 136
        // (incompatible changes) . (backwards compatible functionality) . (backwards compatible bug fixes)
        versionName "77.7.10"
        minSdkVersion 21
        targetSdkVersion 33
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.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'
    }

}
