plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'org.jetbrains.kotlin.android'
    id 'org.jetbrains.dokka' version '2.0.0'
}

android {
    defaultConfig {
        applicationId "eu.fliegendewurst.triliumdroid"
        minSdkVersion 24
        compileSdk 35
        targetSdkVersion 35
        versionCode 19
        versionName "0.99.0-alpha14"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments useTestStorageService: "true"

        buildConfigField "long", "TIMESTAMP", "1739960195000L"
    }

    buildTypes {
        release {
            minifyEnabled true
            // TODO: check if proguard-android-optimize.txt still causes trouble
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            applicationIdSuffix ".debug"
            enableUnitTestCoverage true
            enableAndroidTestCoverage true
        }
    }
    buildFeatures {
        viewBinding true
        buildConfig true
    }
    androidResources {
        generateLocaleConfig = true
    }

    // see https://android.izzysoft.de/articles/named/iod-scan-apkchecks#blobs
    dependenciesInfo {
        // Disables dependency metadata when building APKs.
        includeInApk = false
        // Disables dependency metadata when building Android App Bundles.
        includeInBundle = false
    }

    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    packaging {
        resources.excludes.add("META-INF/versions/9/OSGI-INF/MANIFEST.MF")
    }
    testOptions {
        managedDevices {
            localDevices {
                register("pixel9api35") {
                    device = "Pixel 9"
                    apiLevel = 35
                    systemImageSource = "aosp-atd"
                }
            }
        }
    }
    namespace 'eu.fliegendewurst.triliumdroid'
}

dependencies {
    def nav_version = "2.8.9"

    implementation 'androidx.core:core-ktx:1.16.0'
    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
    implementation "androidx.fragment:fragment-ktx:1.8.6"
    implementation "androidx.viewpager2:viewpager2:1.1.0"
    implementation 'com.google.android.material:material:1.12.0'
    implementation "androidx.preference:preference-ktx:1.2.1"
    implementation "com.squareup.okhttp3:okhttp:4.12.0"
    implementation "com.squareup.okhttp3:okhttp-tls:4.12.0"
//    implementation "com.github.skydoves:colorpickerview:2.3.0"
    implementation "org.bouncycastle:bcprov-lts8on:2.73.7"
    implementation 'com.wdullaer:materialdatetimepicker:4.2.3'

    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.1.5'

    testImplementation "junit:junit:4.13.2"
    androidTestImplementation "androidx.test.ext:junit-ktx:1.2.1"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1"
    androidTestImplementation "androidx.test.espresso:espresso-contrib:3.6.1"
    androidTestImplementation 'androidx.test.espresso:espresso-web:3.6.1'
    androidTestUtil "androidx.test.services:test-services:1.5.0"
}

tasks.register("jacocoTestReport", JacocoReport) {
    dependsOn("testDebugUnitTest")
    dependsOn("pixel9api35DebugAndroidTest")

    reports {
        xml.required.set(false)
        html.required.set(true)
        csv.required.set(false)
    }

    def fileFilter = ["**/R.class", '**/R$*.class', "**/BuildConfig.*", "**/Manifest*.*", "**/*Test*.*", "android/**/*.*", "**/Icon.*"]
    def debugTree = fileTree(dir: "${layout.buildDirectory}/tmp/kotlin-classes/debug", excludes: fileFilter)
    def mainSrc = "${project.projectDir}/src/main/kotlin"

    sourceDirectories.from = files([mainSrc])
    classDirectories.from = files([debugTree])
    executionData.setFrom(fileTree(dir: "$projectDir/build", includes: [
            "outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
            "outputs/managed_device_code_coverage/debug/pixel9api35/coverage.ec"
    ]))
}
