plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
}

android {
    namespace = "m.c.g.a.i_iwara"
    compileSdk = flutter.compileSdkVersion
    ndkVersion "27.0.12077973"

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_21
        targetCompatibility = JavaVersion.VERSION_21
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_21
    }

    defaultConfig {
        applicationId = "m.c.g.a.i_iwara"
        minSdk = 24
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    // 配置正式签名（正式构建时使用）
    signingConfigs {
        release {
            // 这里的路径应该与 GitHub Action 解码后存放的路径一致
            storeFile file("keystore.jks")
            storePassword System.getenv("KEYSTORE_PASSWORD") ?: project.findProperty("MY_KEYSTORE_PASSWORD")
            keyAlias System.getenv("KEY_ALIAS") ?: project.findProperty("MY_KEY_ALIAS")
            keyPassword System.getenv("KEY_PASSWORD") ?: project.findProperty("MY_KEY_PASSWORD")
        }
    }

    buildTypes {
        release {
            // 正式构建时启用正式签名
            signingConfig signingConfigs.release
            minifyEnabled false
            shrinkResources false
        }
        debug {
            signingConfig signingConfigs.debug
        }
    }

    splits {
        abi {
            enable true
            reset()
            include 'arm64-v8a', 'armeabi-v7a', 'x86_64'
            universalApk true
        }
    }

    packagingOptions {
        jniLibs {
            useLegacyPackaging = true
        }
    }
    
    // 构建优化配置
    buildFeatures {
        buildConfig false
    }
    
    // 减少构建输出
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

dependencies {
    implementation 'com.google.errorprone:error_prone_annotations:2.10.0'
    implementation 'com.google.code.findbugs:jsr305:3.0.2'
}

flutter {
    source = "../.."
}
