plugins {
    alias(libs.plugins.android.application)
    id("jacoco") // 1. 新增：应用 JaCoCo 插件（用于生成覆盖率报告）
}

android {
    packaging {
        resources.excludes.add("META-INF/DEPENDENCIES");
        resources.excludes.add("META-INF/NOTICE");
        resources.excludes.add("META-INF/LICENSE");
        resources.excludes.add("META-INF/LICENSE.txt");
        resources.excludes.add("META-INF/NOTICE.txt");
        jniLibs {
            // 对于 .so 文件的 pickFirst
            pickFirsts.add("**/*.so")
        }
    }
    namespace = "net.micode.notes"
    compileSdk {
        version = release(36)
    }

    defaultConfig {
        //包名，标识
        applicationId = "net.micode.notes"
        minSdk = 30
        targetSdk = 36
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

    }


    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
        debug {
            enableUnitTestCoverage = true
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

}
// 3. 新增：配置 JaCoCo 任务，生成 XML 格式的覆盖率报告（SonarQube 需读取 XML 报告）
// 修复2：配置 JaCoCo 任务（解决 main 和 srcDirs 引用错误）
// JaCoCo覆盖率任务（无废弃API警告）
tasks.register<JacocoReport>("jacocoTestReport") {
    dependsOn("testDebugUnitTest")

    reports {
        xml.required = true
        html.required = true
        // 新路径API：覆盖率XML报告路径
        xml.outputLocation = file("${layout.buildDirectory.file("reports/jacoco/testDebugUnitTest/jacocoTestReport.xml").get().asFile.path}")
    }

    val mainSourceSet = android.sourceSets.getByName("main")
    sourceDirectories.setFrom(
        fileTree(
            mapOf(
                "dir" to mainSourceSet.java.srcDirs.first(),
                "exclude" to listOf("**/R.java", "**/BuildConfig.java")
            )
        )
    )

    classDirectories.setFrom(
        fileTree(
            mapOf(
                // 新路径API：编译后的class文件路径
                "dir" to "${layout.buildDirectory.file("intermediates/javac/debug/classes").get().asFile.path}",
                "exclude" to listOf("**/R.class", "**/BuildConfig.class")
            )
        )
    )

    executionData.setFrom(
        // 新路径API：测试执行数据路径
        file("${layout.buildDirectory.file("jacoco/testDebugUnitTest.exec").get().asFile.path}")
    )
}
dependencies {
    implementation(libs.appcompat)
    implementation(libs.material)
    implementation(libs.activity)
    implementation(libs.constraintlayout)
    //implementation(fileTree(mapOf(
    //   "dir" to "D:\\AndroidTools\\AndroidProject\\Notes-master\\httpcomponents-client-4.5.14-bin",
    //    "include" to listOf("*.aar", "*.jar"),
    //    "exclude" to listOf("")
    //)))
    implementation(files("D:\\AndroidTools\\AndroidProject\\Notes-master\\httpcomponents-client-4.5.14-bin\\lib\\httpclient-osgi-4.5.14.jar"))
    implementation(files("D:\\AndroidTools\\AndroidProject\\Notes-master\\httpcomponents-client-4.5.14-bin\\lib\\httpclient-win-4.5.14.jar"))
    implementation(files("D:\\AndroidTools\\AndroidProject\\Notes-master\\httpcomponents-client-4.5.14-bin\\lib\\httpcore-4.4.16.jar"))
    testImplementation(libs.junit)
    androidTestImplementation(libs.ext.junit)
    androidTestImplementation(libs.espresso.core)
    //新增依赖

    implementation("jp.wasabeef:richeditor-android:2.0.0")
    // Vosk离线语音识别依赖
    implementation("net.java.dev.jna:jna:5.13.0@aar") // Vosk需要JNA

}