plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"
    id "com.google.firebase.crashlytics"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 35
    ndkVersion "27.0.12077973"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 34            
        ndk {
            debugSymbolLevel 'FULL'
            abiFilters 'armeabi-v7a', 'arm64-v8a'
        }
        /// legacy material-lightmeter ap stopped updating after 60022
        /// 7xxxx means that it is a new app
        versionCode 70000 + flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }

    flavorDimensions "app"
    productFlavors {
        dev {
            resValue "string", "app_name", "Lightmeter (DEV)"
            dimension "app"
            signingConfig signingConfigs.release
            applicationIdSuffix ".dev"
        }
        prod {
            resValue "string", "app_name", "Lightmeter"
            dimension "app"
            signingConfig signingConfigs.release
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            shrinkResources true
            ndk {
                debugSymbolLevel 'FULL'
                abiFilters 'armeabi-v7a', 'arm64-v8a'
            }
        }
    }
    namespace 'com.vodemn.lightmeter'
}

flutter {
    source '../..'
}

dependencies {
    implementation "com.android.billingclient:billing-ktx:6.0.0"
    implementation "com.google.firebase:firebase-analytics:17.4.1"
}
