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')
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 {
    namespace = "eu.hydrologis.smash"

    defaultConfig {
        applicationId "eu.hydrologis.smash"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion 35
        compileSdk 35
//        buildToolsVersion = "34.0.0"
        
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            // useProguard true
            // signingConfig signingConfigs.release
            signingConfig signingConfigs.debug
        }
    }
    lint {
        checkReleaseBuilds false
        disable 'InvalidPackage'
    }
}


// START WORKAROUND for hanging build
// this change also brings "multiDexEnabled true" in defaultConfig
configurations.configureEach {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-location:17.0.0'
    }
}
// END WORKAROUND

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.5.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    // required to avoid crash on Android 12 API 31
    // implementation 'androidx.work:work-runtime-ktx:2.7.0'
              // For Java
    implementation 'androidx.work:work-runtime:2.9.0'

    // For Kotlin
    implementation 'androidx.work:work-runtime-ktx:2.9.0'
}
