plugins {
  id "com.android.application"
    // START: FlutterFire Configuration
  id "com.google.gms.google-services"
  id "com.google.firebase.crashlytics"
  id 'com.google.firebase.firebase-perf'
    // END: FlutterFire Configuration
  id "kotlin-android"
  id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
rootProject.file('local.properties').withInputStream { localProperties.load(it) }

def keystoreProperties = new Properties()
rootProject.file('key.properties').withInputStream { keystoreProperties.load(it) }

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
def flutterVersionName = localProperties.getProperty('flutter.versionName')
def buildNumber = System.getenv("BUILD_NUMBER") ?: "0"

android {
  namespace "com.evanlu.possystem"
  compileSdkVersion flutter.compileSdkVersion
  ndkVersion flutter.ndkVersion

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_17
    targetCompatibility JavaVersion.VERSION_17
  }

  kotlinOptions {
    jvmTarget = JavaVersion.VERSION_17
  }

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

  defaultConfig {
    applicationId "com.evanlu.possystem"
    // default: flutter.minSdkVersion
    // but firebase auth requires 23
    minSdkVersion = flutter.minSdkVersion
    targetSdkVersion flutter.targetSdkVersion
    multiDexEnabled true
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
  }

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

  buildTypes {
    release {
      minifyEnabled true
      signingConfig signingConfigs.release
    }

    debug {
      debuggable true
      signingConfig signingConfigs.release
    }
  }

  flavorDimensions "mode"

  productFlavors {
    prod {
      dimension "mode"
    }

    dev {
      dimension "mode"
      versionNameSuffix "-dev+" + buildNumber
    }
  }
  lintOptions {
    disable 'InvalidPackage'
    checkReleaseBuilds false
  }
}

flutter {
  source '../..'
}

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
  // kotlin version
  implementation "org.jetbrains.kotlin:kotlin-stdlib:2.1.21"
  implementation "androidx.multidex:multidex:2.0.1"
}

// This must appear at the bottom of the file
apply plugin: 'com.google.firebase.crashlytics'
