plugins {
    id "com.android.application"
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

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

android {
    namespace = "io.chameleon.ultra"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = "28.2.13676358"

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId = "io.chameleon.ultra"
        minSdk = flutter.minSdkVersion
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

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

    buildTypes {
        release {
            if (keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']).exists() : false) {
                println "Info: upload-keystore.jks found. Signing for release."
                signingConfig = signingConfigs.release
            }
            else {
                println "Warning: upload-keystore.jks not found. Signing for debug."
                signingConfig = signingConfigs.debug
            }
        }
    }

    externalNativeBuild {
        cmake {
            path "../../src/CMakeLists.txt"
        }
    }
}

flutter {
    source = "../.."
}

dependencies {
    implementation "com.polidea.rxandroidble2:rxandroidble:1.17.2"
}