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 KEYSTORE_FILE = rootProject.file('./key.jks')
def GITHUB_BUILD = System.getenv("GITHUB_ACTIONS") == "true" && KEYSTORE_FILE.exists()
def LOCAL_KEY_PRESENT = project.hasProperty('SIGNING_KEY_FILE') && rootProject.file(SIGNING_KEY_FILE).exists()

android {
    namespace = "magic.epaper"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

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

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_17
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "magic.epaper"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = 26
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }



    signingConfigs {
        if (GITHUB_BUILD) {
            release {
                storeFile KEYSTORE_FILE
                storePassword System.getenv("STORE_PASS")
                keyAlias System.getenv("ALIAS")
                keyPassword System.getenv("KEY_PASS")
            }
        } else if (LOCAL_KEY_PRESENT) {
            release {
                storeFile rootProject.file(SIGNING_KEY_FILE)
                storePassword STORE_PASS
                keyAlias ALIAS
                keyPassword KEY_PASS
            }
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            if (LOCAL_KEY_PRESENT || GITHUB_BUILD) {
                signingConfig signingConfigs.release
            }
        }
    }
}

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

dependencies {
    implementation files("libs/waveshare-nfc/NFC.jar")
}
