apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion '27.0.3'
    useLibrary  'org.apache.http.legacy'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 24
        versionCode 1020
        versionName "1.0.2"
    }


    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
            aidl.srcDirs = ['src']
            jniLibs.srcDirs = ['libs']
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:24.2.0'

    compile 'com.google.code.gson:gson:2.+'
    compile 'com.netflix.rxjava:rxjava-core:0.17.+'
    compile 'com.netflix.rxjava:rxjava-android:0.17.+'
    compile 'com.squareup.okhttp:okhttp:2.1.+'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.+'
    compile 'com.squareup.retrofit:retrofit:1.7.+'
    compile 'com.squareup.picasso:picasso:2.4.+'
    compile 'com.squareup:otto:1.3.5'
    compile 'com.jakewharton:butterknife:6.0.+'
    compile 'org.apache.commons:commons-io:1.3.2'

    compile 'joda-time:joda-time:2.5'

    compile project(':imkit')
    compile project(':imsdk')
    compile project(':asynctcp')
}

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
}


def appendVersionNameVersionCode(variant, defaultConfig) {
    //check if staging variant
    if (variant.name == android.buildTypes.release.name) {
        if (variant.buildType.zipAlignEnabled) {
            variant.outputs.each{output ->
                def outputFile = output.outputFile
                if (outputFile != null && outputFile.name.endsWith('.apk')){
                    def fileName = outputFile.name.replace(".apk", "-v" + defaultConfig.versionName + ".apk")
                    output.outputFile = new File(outputFile.parent, fileName)
                }

            }
        }
       /* def file = variant.buildType.packageApplication.outputFile
        def fileName = file.name.replace(".apk", "-v" + defaultConfig.versionName + ".apk")
        variant.packageApplication.outputFile = new File(file.parent, fileName)*/
    }
}
