apply plugin: 'com.android.application'

//定义打包时间函数
def packageTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}

android {
    compileSdkVersion Integer.parseInt(ANDROID_BUILD_COMPILE_SDK_VERSION)
    buildToolsVersion ANDROID_BUILD_TOOLS_VERSION

    signingConfigs {
        debug {

        }
        release {
            //storeFile file("../yourapp.keystore")
            //storePassword "your password"
            //keyAlias "your alias"
            //keyPassword "your password"

            //setting your signing.properties
            //first, add signing.properties to ./app/
            //second, add property STORE_FILE, STORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD
        }
    }

    defaultConfig {
        applicationId "com.ecloud.android.xreap"
        minSdkVersion Integer.parseInt(MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION)
        versionCode Integer.parseInt(VERSION_CODE)
        versionName VERSION_NAME

        // dex突破65535的限制
        multiDexEnabled true
    }
    buildTypes {
        debug {
            buildConfigField "boolean", "LOG_DEBUG", "true"//是否输出LOG信息
            buildConfigField "String", "API_HOST", "\"http://api.test.com\""//API Host
            minifyEnabled false
            zipAlignEnabled true
            shrinkResources true
            signingConfig signingConfigs.debug
        }

        release {
            buildConfigField "boolean", "LOG_DEBUG", "false"//是否输出LOG信息
            buildConfigField "String", "API_HOST", "\"http://api.release.com\""//API Host
            minifyEnabled false//混淆编译
            zipAlignEnabled true
            //移除无用的资源文件
            shrinkResources true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    lintOptions {
        disable 'InvalidPackage'
        abortOnError false
    }

    //修改生成的最终文件名
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                File outputDirectory = new File(outputFile.parent);
                def fileName
                if (variant.buildType.name == "release") {
                    // 输出apk名称为app_v1.0.0_2015-06-15_playStore.apk
                    fileName = "app_v${defaultConfig.versionName}_${packageTime()}_${variant.productFlavors[0].name}.apk"
                } else {
                    fileName = "app_v${defaultConfig.versionName}_${packageTime()}_beta.apk"
                }
                output.outputFile = new File(outputDirectory, fileName)
            }
        }
    }

    productFlavors {
        playStore {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "playStore"]
        }
        miui {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "miui"]
        }
        wandoujia {
            manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"]
        }
    }

//批量替换
//    productFlavors {
//        palyStore {}
//        miui {}
//        wandoujia {}
//    }
//
//    productFlavors.all {
//        flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
//    }
}

def propFile = project.rootProject.file('signing.properties');
if (propFile.exists()) {
    def Properties props = new Properties()
    props.load(new FileInputStream(propFile))
    if (props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
            props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {
        android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
        android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
    } else {
        android.buildTypes.release.signingConfig = null
    }
} else {
    android.buildTypes.release.signingConfig = null
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:cardview-v7:21.0.3'
    compile 'com.android.support:recyclerview-v7:21.0.3'
//    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.android.support:multidex:1.0.0'

    //View注解   代码地址-----> https://github.com/JakeWharton/butterknife
    compile 'com.jakewharton:butterknife:6.1.0'
    //图片加载  代码地址-----> https://github.com/square/picasso
    compile 'com.squareup.picasso:picasso:2.5.2'
    //API网络请求注解库    代码地址-----> https://github.com/square/retrofit
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    //网络请求库 代码地址-----> https://github.com/square/okhttp
    compile 'com.squareup.okhttp:okhttp:2.2.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
    //消息通知数据更新（类似Broadcast）  代码地址-----> https://github.com/greenrobot/EventBus
    compile 'de.greenrobot:eventbus:2.4.0'
    //圆形头像  代码地址-----> https://github.com/hdodenhof/CircleImageView
    compile 'de.hdodenhof:circleimageview:1.2.1'
    //解析JSON数据  代码地址-----> https://code.google.com/p/google-gson/
    compile 'com.google.code.gson:gson:2.3.1'
    //弹出提示信息    代码地址-----> https://github.com/johnkil/Android-AppMsg
    compile 'com.github.johnkil.android-appmsg:appmsg:1.2.0'
    //SuperRecyclerView    代码地址-----> https://github.com/Malinskiy/SuperRecyclerView
    compile 'com.malinskiy:superrecyclerview:1.1.0'
    //超强滚动效果View    代码地址-----> https://github.com/ksoichiro/Android-ObservableScrollView
    compile 'com.github.ksoichiro:android-observablescrollview:1.5.1'
}
