apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
apply plugin: 'com.jakewharton.hugo'
apply plugin: 'android-apt'

description "RJcenter"
version "1.1.0"

println "----------输出基础配置信息----------"
println project
println name
println path
println description
println projectDir
println buildDir
println group
println version
println ant
println "------------------------------"

//--------------------------------
//        project ':sample'
//sample
//:sample
//RJcenter
//F:\AsDemo\RJcenter\sample
//F:\AsDemo\RJcenter\sample\build
//RJcenter
//1.1.0
//org.gradle.api.internal.project.DefaultAntBuilder@6a256fc
//--------------------------------

repositories {
    println "in a closure 1"
}
repositories() { println "in a closure 2" }
repositories({ println "in a closure 3" })
println "------------------------------"

def build_time = buildTime()
def build_host = hostName()
def java_version = javaVersion()
def os_name = osName()
def isMac = isMacOs()
def build_revision = isMac ? macGitVersion() : winGitVersion()
def keyFilePath = isMac ? '/Users/angcyo/Project/y2angcyo.jks' : 'F:/angcyo/y2angcyo.jks'

hi build_time
hi build_host
hi java_version
hi os_name
hi build_revision
hi "是否是苹果系统:" + isMac
hi "密钥文件路径:" + keyFilePath

/*是否激活滑动删除主题*/
def slider = false

def appName

Properties props = new Properties()
if (project.hasProperty("dudu.properties")
        && new File(project.property("dudu.properties")).exists()) {
    props.load(new FileInputStream(file(project.property("dudu.properties"))))

    println props['keystore']
}

android {
    compileSdkVersion Integer.parseInt(rootProject.R_COMPILE_SDK_VERSION)
    buildToolsVersion rootProject.R_BUILD_TOOLS_VERSION
    defaultConfig {
        applicationId "com.angcyo.sample"
        minSdkVersion Integer.parseInt(R_MIN_SDK_VERSION)
        targetSdkVersion Integer.parseInt(R_TARGET_SDK_VERSION)
        versionCode 10
        versionName "1.3.0 beta"

        resValue "string", "build_time", build_time
        resValue "string", "build_host", build_host
        resValue "string", "build_revision", build_revision
        resValue "string", "java_version", java_version
        resValue "string", "os_name", os_name

        multiDexEnabled true

        buildConfigField "boolean", "slider", String.valueOf(slider)

        if (slider) {
            manifestPlaceholders = [app_theme: "@style/AppTheme"]
        } else {
            manifestPlaceholders = [app_theme: "@style/AppThemeNoSlidr"]
        }

//        ndk {
//            abiFilters "armeabi-v7a"
//        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    signingConfigs {
        config {
            keyAlias 'angcyo'
            keyPassword 'angcyo'
            storeFile file(keyFilePath)
            storePassword 'angcyo'
        }
    }
    buildTypes {
        // minifyEnabled 混淆处理
        // shrinkResources 去除无用资源
        // signingConfig 签名
        // proguardFiles 混淆配置
        // applicationIdSuffix 增加APP ID的后缀
        // debuggable 是否保留调试信息
        // ... ...
        release {
            manifestPlaceholders = [app_name: "@string/app_name_release"]
            buildConfigField "String", "buildType", "\"${name}\""
//            applicationIdSuffix ".release"
            minifyEnabled false
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
        debug {
            buildConfigField "String", "buildType", "\"${name}\""
            manifestPlaceholders = [app_name: "@string/app_name_debug"]
//            applicationIdSuffix ".debug"
            minifyEnabled false
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            pseudoLocalesEnabled false
        }
    }
    lintOptions {
        quiet true
        abortOnError false
        ignoreWarnings true
        disable 'MissingTranslation'
        disable 'GoogleAppIndexingWarning'
    }
    dexOptions {
        preDexLibraries = false
        jumboMode = true
        incremental true
        javaMaxHeapSize "4g"
        dexInProcess false
    }
    getApplicationVariants().all { variant ->
        variant.outputs.each { output ->
            def time
            if (!variant.buildType.name.equalsIgnoreCase("debug")) {
                time = "." + getTime()
            } else {
                time = ""
            }
            appName = "RJcenter-${variant?.productFlavors[0]?.name}-${variant.buildType.name}-${variant.versionName}${time}.apk"
            output.outputFile = new File(output.outputFile.parent, appName)
        }
    }
    sourceSets {
        main {
            java.srcDirs = ['src/main/java', 'src/main/aidl']
        }
    }
    //${variant.productFlavors[0].name}
    compileOptions {
        encoding "UTF-8"
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }
    repositories {
        flatDir {
            dirs 'libs'
        }
    }

/*    allprojects {
        gradle.projectsEvaluated {
            tasks.withType(JavaCompile) {
                options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
            }
        }
    }*/

    packagingOptions {
        exclude 'META-INF/LICENSE'
    }

//    useLibrary 'org.apache.http.legacy'

/*        aaptOptions {
        cruncherEnabled = false
    }

    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false*/
}

dependencies {
    compile(name: 'aaaa-1.0', ext: 'aar')
    //    compile name: 'volley', ext: 'aar'
    //    compile 'com.angcyo:L:1.1.0'
    //    compile 'com.rsen:rsen:0.0.1'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    //    compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
    compile project(':rsen')
    //    去掉重复依赖
    //    compile 'com.alibaba.fastjson.latest.integration' {
    //        exclude module: 'annotations', group: 'com.google.android'
    //    }
    compile project(':bmob')
    compile 'com.cocosw:query:0.2.2'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    testCompile 'junit:junit:4.12'

    compile 'com.jakewharton:butterknife:8.4.0'
    apt 'com.jakewharton:butterknife-compiler:8.4.0'
}

/*task javadocs(type: Javadoc) {
    hi "javadocs  --start"

    source = android.sourceSets.main.java.srcDirs
    classpath += configurations.compile
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))

    options {
        encoding "UTF-8"
        charSet "UTF-8"
        author true
        version true
        links "http://docs.oracle.com/javase/7/docs/api"
        title "HKCloud_Studio"
    }

    hi "javadocs  --end"
}*/

/*tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
    options.compilerArgs << "-Xlint:deprecation"
    options.compilerArgs << "-Xlint:unchecked"
}*/

hi "------gradle build---------end"

task makeApk {
    doLast {
        def versionName = android.defaultConfig.versionName
        hi appName
        copy {
            from "./build/outputs/apk/${appName}"
            into "../"
            rename {
                appName
            }
        }
    }
}
