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

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')
def flutterVersionName = localProperties.getProperty('flutter.versionName')

def secretProperties = new Properties()
secretProperties.setProperty("SIGNING_KEYSTORE_PATH", "${System.getenv("SIGNING_KEYSTORE_PATH")}")
secretProperties.setProperty("SIGNING_KEYSTORE_PASSWORD", "${System.getenv("SIGNING_KEYSTORE_PASSWORD")}")
secretProperties.setProperty("SIGNING_KEY_ALIAS", "${System.getenv("SIGNING_KEY_ALIAS")}")
secretProperties.setProperty("SIGNING_KEY_PASSWORD", "${System.getenv("SIGNING_KEY_PASSWORD")}")

android {
    namespace = "agersant.polaris"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

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

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        applicationId "agersant.polaris"
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            storeFile file("${secretProperties["SIGNING_KEYSTORE_PATH"]}")
            storePassword "${secretProperties["SIGNING_KEYSTORE_PASSWORD"]}"
            keyAlias "${secretProperties["SIGNING_KEY_ALIAS"]}"
            keyPassword "${secretProperties["SIGNING_KEY_PASSWORD"]}"
        }
    }

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

flutter {
    source '../..'
}

