plugins {
    id 'com.android.application'
}

ext {
    /* Version code for *next* release, bump *after* a release is created. */
    // 1 or more digits
    versionMajor = 1
    // exactly 2 digit
    versionMinor = 0
    // exactly 2 digits
    versionFeature = 44
    // exactly 2 digits
    versionBuild = 1
}

def setupSigning(deviceName) {
    def ksFile = rootProject.file("./keystore/keystore.${deviceName}.properties")
    def props = new Properties()
    if (ksFile.canRead()) {
        props.load(new FileInputStream(ksFile))

        if (props != null) {
            android.signingConfigs."${deviceName}".storeFile file(props['storeFile'])
            android.signingConfigs."${deviceName}".keyPassword props['keyPassword']
            android.signingConfigs."${deviceName}".keyAlias props['keyAlias']
            android.signingConfigs."${deviceName}".storePassword props['storePassword']
            println "The key for device ${deviceName} has been setup"
        } else {
            println 'some entries in \'keystore.properties\' not found!'
        }
    } else {
        println '\'keystore.properties\' not found!'
    }
}

android.signingConfigs.whenObjectAdded { signing ->
    setupSigning(signing.name)
}

android {
    signingConfigs {
        UTE_Sample
    }

    compileSdkVersion 34
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.unitech.unitechrfidsample"
        minSdkVersion 28
        targetSdkVersion 34

        versionCode versionMajor * 1000000 + versionMinor * 10000 + versionFeature * 100 + versionBuild

        if (versionBuild > 0) {
            versionName "${versionMajor}.${versionMinor}.${versionFeature}.${versionBuild}"
        } else {
            versionName "${versionMajor}.${versionMinor}.${versionFeature}"
        }

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.UTE_Sample
        }
        debug {
            signingConfig signingConfigs.UTE_Sample
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def appName = "unitechRFIDSample"
            def versionName = variant.versionName

            if (variant.buildType.name == "debug")
                outputFileName = "${appName}_${versionName}_debug.apk"
            else
                outputFileName = "${appName}_${versionName}.apk"
        }
    }
    buildFeatures {
        viewBinding true
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation 'org.tinylog:tinylog-api:2.4.1'
    implementation 'org.tinylog:tinylog-impl:2.4.1'

    implementation(name: "unitechRFID_v1.0.44.1", ext: "aar")
    implementation files('libs/UnitechSDK_1.2.35.jar')
}