apply plugin: 'com.android.application'

def releaseTime() {
    return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.jun.elephant"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 5
        versionName "1.0.2"

        buildConfigField("String", "CLIENT_ID", "\"${CLIENT_ID}\"")
        buildConfigField("String", "CLIENT_SECRET", "\"${CLIENT_SECRET}\"")
        buildConfigField("String", "API_BASE_URL", "\"${API_BASE_URL}\"")

        manifestPlaceholders = [UMENG_APPKEY : "\"${UMENG_APPKEY}\"",
                                UMENG_CHANNEL_VALUE : "\"${UMENG_CHANNEL_VALUE}\""]

        println("CLIENT_ID ========== " + "\"${CLIENT_ID}\"")
        println("CLIENT_SECRET ========== " + "\"${CLIENT_SECRET}\"")
        println("API_BASE_URL ========== " + "\"${API_BASE_URL}\"")
        println("UMENG_APPKEY ========== " + "\"${UMENG_APPKEY}\"")
    }

    //忽略 lint 错误
    lintOptions {
        abortOnError false
    }

    signingConfigs {

        debug {
            storeFile file("../debug.jks")
            storePassword '111111'
            keyAlias 'Jun'
            keyPassword '111111'
        }

        release {
            def signingFile = file("../signing.properties")
            if (signingFile.canRead()) {
                def Properties properties = new Properties()
                properties.load(new FileInputStream(signingFile))

                try {
                    storeFile file(properties['STORE_FILE'])
                    storePassword properties['STORE_PASSWORD']
                    keyAlias properties['KEY_ALIAS']
                    keyPassword properties['KEY_PASSWORD']

                    println "RELEASE_BUILD: Signing..."
                } catch (e) {
                    throw new InvalidUserDataException("You should define STORE_FILE and STORE_PASSWORD and KEY_ALIAS and KEY_PASSWORD in signing.properties.")
                }

            } else {
                println "RELEASE_BUILD: signing.properties not found"
            }
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
            signingConfig signingConfigs.debug
            //显示 Log
            buildConfigField "boolean", "LOG_DEBUG", "true"

            matchingFallbacks = ['release', 'debug']
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            //不显示 Log
            buildConfigField "boolean", "LOG_DEBUG", "false"
            //移除无用的 Resource
            shrinkResources false
            //资源文件按4字节对齐
            zipAlignEnabled true
            //关闭调试
            debuggable false

            // 多渠道打包
            applicationVariants.all { variant ->
                variant.outputs.all { output ->
                    def outputFile = output.outputFile
                    if (outputFile != null && outputFile.name.endsWith('.apk')) {
                        // 输出apk名称为Elephant_v1.0_2016-10-11_fir.apk
                        def fileName = "Elephant_v${defaultConfig.versionName}_${releaseTime()}_${variant.productFlavors.name}.apk"
                        output.outputFileName = new File(outputFile.parent, fileName)
                    }
                }
            }
            matchingFallbacks = ['release', 'debug']
        }

        innerTest {
            matchingFallbacks = ['debug', 'release']
        }

        //渠道
        productFlavors.all {
            fir {
                manifestPlaceholders = [UMENG_CHANNEL_VALUE: "fir", UMENG_APPKEY: UMENG_APPKEY]
            }
        }
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
    maven {
        url "https://jitpack.io"
    }

    jcenter()
    mavenCentral()  // GPUImage for Android

    maven {
        url "https://s3.amazonaws.com/repo.commonsware.com"
    }
}

def SUPPORT_VERSION = "27.0.2"

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:' + SUPPORT_VERSION
    compile 'com.android.support:design:' + SUPPORT_VERSION
    compile 'com.android.support:cardview-v7:' + SUPPORT_VERSION
    compile 'com.android.support:support-v4:' + SUPPORT_VERSION
    compile 'com.android.support:recyclerview-v7:' + SUPPORT_VERSION
    compile 'com.android.support:percent:' + SUPPORT_VERSION
    implementation project(':liraries:ptr-lib')
    implementation project(':liraries:markdown')
    // If you want to use the GPU Filters
    //RxJava 与 Retrofit
    //辅助
    //    compile 'eu.unicate.android:retroauth:1.0.4'
    compile('com.github.afollestad.material-dialogs:core:0.8.5.5@aar') {
        transitive = true
    }
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'cn.bingoogolapple:bga-badgeview:1.1.3@aar'
    compile 'com.melnykov:floatingactionbutton:1.3.0'
    compile 'jp.wasabeef:glide-transformations:2.0.0'
    compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'io.reactivex:rxjava:1.1.7'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
    compile 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
    compile 'me.dm7.barcodescanner:zxing:1.8.4'
    compile 'com.facebook.fresco:fresco:0.13.0'
    compile 'com.github.polok.localify:localify:1.0.0'
    compile 'com.github.ongakuer:PhotoDraweeView:a14f105aaa'
    compile 'com.commonsware.cwac:anddown:0.2.4'
    compile 'com.umeng.analytics:analytics:6.1.3'
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    compile 'com.squareup.okio:okio:1.6.0'
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.github.orhanobut:logger:1.12'
    compile 'com.pnikosis:materialish-progress:1.7'
    compile 'com.android.support:support-v4:27.0.2'
    testCompile 'junit:junit:4.12'
}
