apply plugin: 'com.android.application'
apply plugin: 'com.akaita.android.easylauncher'
apply plugin: 'com.jakewharton.hugo'
apply from: '../dependencies.gradle'
def PRODUCT_NAME = "陨石"

// Create a variable called keystorePropertiesFile, and initialize it to your
// keystore.properties file, in the rootProject folder.
def keystorePropertiesFile = rootProject.file("keystore.properties")

// Initialize a new Properties() object called keystoreProperties.
def keystoreProperties = new Properties()

// Load your keystore.properties file into the keystoreProperties object.
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {
    compileSdkVersion versions.compileSdk
    buildToolsVersion versions.buildTools
    defaultConfig {
        applicationId "com.firelotus.meteorite"
        minSdkVersion versions.minSdk
        targetSdkVersion versions.targetSdk
        versionCode versions.versionCode
        versionName versions.versionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        flavorDimensions "" //解决Gradle3.0 Error:All flavors must now belong to a named flavor
        multiDexEnabled true
    }
    signingConfigs {
        config {
            keyAlias keystoreProperties['KEY_ALIAS']
            keyPassword keystoreProperties['KEY_PASSWORD']
            storeFile file(keystoreProperties['STORE_FILE'])
            storePassword keystoreProperties['STORE_PASSWORD']
        }
    }
    buildTypes {
        debug {
            // 混淆
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            debuggable true // 保留debug信息
            //打开log输出
            buildConfigField "boolean", "LOG_DEBUG", "true"
            signingConfig signingConfigs.config
            manifestPlaceholders = [APP_NAME: "@string/app_name"]
            //如果利用applicationIdSuffix支持生成多个APP，则需利用类似${APP_NAME}的占位符，配置多个key值，如推送，支付等
            //applicationIdSuffix ".debug"
        }
        release {
            // 混淆
            minifyEnabled true
            // Zipalign优化
            zipAlignEnabled true
            // 移除无用的resource文件
            shrinkResources true
            debuggable false // 不保留debug信息
            //关闭log输出
            buildConfigField "boolean", "LOG_DEBUG", "false"
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
            manifestPlaceholders = [APP_NAME: "@string/app_name"]
        }
    }

    // 指定输出的apk名
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            def outputFile = output.outputFile
            // 打包类型
            def buildTypeName = variant.buildType.name

            def BUILD_TIME_FORMAT = new Date().format("yyyyMMdd", TimeZone.getTimeZone("UTC"))

            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                // 包名称
                def flavorName = variant.productFlavors[0].name
                // 版本名称
                def versionName = defaultConfig.versionName
                // 开发环境
                buildConfigField "String", "APP_ENV", "\"${flavorName}\""
                // yourapkname_release_myapk_ver1.0.0_build20130312.apk 输出格式
                def fileName = "${PRODUCT_NAME}_V${versionName}_${buildTypeName}_${flavorName}_${BUILD_TIME_FORMAT}.apk"

                outputFile = new File(outputFile.parent/* + "/${buildTypeName}"*/, fileName)
            }
        }
    }

    productFlavors {
        //生产环境
        rls {
            buildConfigField "String", "BASE_URL", "\"http://gank.io/api/\""
        }
        //开发环境
        dev {
            buildConfigField "String", "BASE_URL", "\"http://dev.gank.io/api/\""
        }
        //测试环境
        sit {
            buildConfigField "String", "BASE_URL", "\"http://sit.gank.io/api/\""
        }
    }

    lintOptions {
        abortOnError false
        checkReleaseBuilds false
    }

    dexOptions {
        javaMaxHeapSize "4g"
        jumboMode true
        //incremental true
    }
}

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

    //leakcanary
    debugCompile "com.squareup.leakcanary:leakcanary-android:${versions.leakcanary}"
    releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:${versions.leakcanary}"
    // Optional, if you use support library fragments:
    debugCompile "com.squareup.leakcanary:leakcanary-support-fragment:${versions.leakcanary}"

    annotationProcessor "com.jakewharton:butterknife-compiler:${versions.butterKnife}"

    annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${versions.dbflow}"

    ////https://github.com/amitshekhariitbhu/Android-Debug-Database
    //直接查看手数据库   手机http://手机IP:8080    手机需与电脑在同一网段
    debugCompile "com.amitshekhar.android:debug-db:${versions.debugDb}",{
        exclude group: 'com.google.code.gson', module: 'gson'
    }
}

//更改程序图标
easylauncher {
    defaultFlavorNaming = true // Use flavor name for default ribbon, instead of the type name
    variants {
        devRelease {
            filters = customColorRibbonFilter("dev", "#6600CC")
            enable true
        }
        sitRelease {
            filters = customColorRibbonFilter("sit", "#6600CC")
            enable true
        }
    }
}