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 keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

android {
    namespace 'r.r.refreezer'
    compileSdk 35
    //ndkVersion flutter.ndkVersion
    ndkVersion "27.0.12077973"
    buildFeatures.buildConfig = true
    
    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        // Sets Java compatibility to Java 17
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    kotlinOptions {
        jvmTarget = "17"
    }

    defaultConfig {
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        applicationId "r.r.refreezer"
        minSdk 21
        targetSdk 35
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

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

    buildTypes {
        release {
            signingConfig signingConfigs.release
            shrinkResources false
            minifyEnabled false
        }
        debug {
            applicationIdSuffix '.debug'
            versionNameSuffix '-debug'
        }
    }

    /*externalNativeBuild {
        ndkBuild {
            path file('src/main/jni/Android.mk')
        }
    }*/
    lint {
        disable 'InvalidPackage'
    }
}

dependencies {
    implementation files('libs/extension-flac.aar') // Required for older Android versions (< android 10?)
    implementation("androidx.activity:activity-ktx:1.10.1")
    //implementation group: 'net.jthink', name: 'jaudiotagger', version: '3.0.1' // requires java 8 so no android 6
    implementation group: 'net.jthink', name: 'jaudiotagger', version: '2.2.5'
    implementation group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1'
    implementation 'androidx.documentfile:documentfile:1.1.0'
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.1.5'
}

flutter {
    source '../..'
}
