plugins {
    id "com.android.application"
    id "org.jetbrains.kotlin.android"
    id "com.google.gms.google-services"
    id "dev.flutter.flutter-gradle-plugin" // 🔥 HARUS PALING BAWAH
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
    localProperties.load(new FileInputStream(localPropertiesFile))
}

def flutterVersionCode = localProperties.getProperty("flutter.versionCode") ?: "1"
def flutterVersionName = localProperties.getProperty("flutter.versionName") ?: "1.0"

android {
    namespace "com.example.sigesit"
    compileSdk 34

    defaultConfig {
        applicationId "com.example.sigesit"

        // 🔥 FIX ERROR PROVIDER (WAJIB DIGANTI ANGKA)
        minSdkVersion flutter.minSdkVersion
        targetSdk 34

        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName

        multiDexEnabled true
    }

    // 🔥 WAJIB untuk AGP 8+
    buildFeatures {
        buildConfig true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
            minifyEnabled false
            shrinkResources false
        }
    }

    // 🔥 TAMBAHAN (rename file APK)
    applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "Smart Selada.apk"
        }
    }
}

flutter {
    source "../.."
}

dependencies {
    implementation platform('com.google.firebase:firebase-bom:33.5.1')

    implementation 'com.google.firebase:firebase-database-ktx'
    implementation 'com.google.firebase:firebase-analytics-ktx'

    implementation 'androidx.multidex:multidex:2.0.1'
}