plugins {
    id 'com.gladed.androidgitversion' version '0.4.14'
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

//return a BuildConfigField from a properties file.
def static getBuildConfigField(String property){
    def propFile = new File("keystore.properties")
    def value

    if(propFile.exists()) {
        Properties properties = new Properties()
        properties.load(new FileInputStream(propFile))
        value = "\"" + properties.getProperty(property) + "\""
    } else {
        value = "\"" + System.getenv(property) + "\""
    }

    return value
}

def build_param = "${build}"

if (build_param != "prod") {
    //exclude development build
    android.variantFilter { variant ->
        if (variant.buildType.name == 'prod') {
            variant.setIgnore(true)
        }
    }
} else {
    //exclude all except development build
    android.variantFilter { variant ->
        if (variant.buildType.name != 'prod') {
            variant.setIgnore(true)
        }
    }
}

android {
    compileSdkVersion 32
    buildToolsVersion "32.0.0"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    lintOptions {
        abortOnError false
    }

    defaultConfig {
        applicationId "es.ugr.swad.swadroid"
        versionName androidGitVersion.name()
        versionCode androidGitVersion.code()

        minSdkVersion 24
        targetSdkVersion 32

        testApplicationId "es.ugr.swad.swadroid.test"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"

        buildConfigField "String", "SWAD_APP_KEY", getBuildConfigField("SWAD_APP_KEY")
    }

    buildTypes {
        prod {
            minifyEnabled true
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.code.ksoap2-android:ksoap2-android:3.6.4'
    implementation 'commons-io:commons-io:2.11.0'
    implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
    implementation 'com.journeyapps:zxing-android-embedded:4.3.0@aar'
    implementation 'com.google.zxing:core:3.5.0'
    implementation 'com.google.code.gson:gson:2.9.0'
    implementation 'com.google.android.material:material:1.6.0'
    implementation platform('com.google.firebase:firebase-bom:30.0.2')
    implementation 'com.google.firebase:firebase-analytics'
}
