android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    defaultConfig {
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName
        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }

    dataBinding {
        enabled true
    }
/**
 * 签名设置
 */
    signingConfigs {
        release {
            storeFile file(RELEASE_STORE_FILE)
            storePassword RELEASE_STORE_PASSWORD
            keyAlias "聊球"
            keyPassword RELEASE_KEY_PASSWORD
        }
    }

    buildTypes {
        release {
            ndk {
                abiFilters "armeabi-v7a"
//                abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
            }
            signingConfig signingConfigs.release
            buildConfigField "String", "BaseUrl", "\"" + BaseUrl + "\""
            //移除无用的resource文件 shrinkResources依赖于minifyEnabled，必须和minifyEnabled一起用
            proguardFiles getDefaultProguardFile('proguard-android.txt'), PROGUARD_RULES
            minifyEnabled true //是否混淆
            shrinkResources false
            zipAlignEnabled true //对齐操作，使得我们的程序在Android系统中运行得更快
            buildConfigField "Boolean", "allowBackup", "false"
            manifestPlaceholders = [AMAP_KEY: "3ac68165c303d56418c5ed375884f544", allowBackup: "false"]
        }

        debug {
            ndk {
                abiFilters "armeabi-v7a"
//                abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
            }
            signingConfig signingConfigs.release
//            buildConfigField "String", "BaseUrl", "\"http://192.168.0.42/\""
            buildConfigField "String", "BaseUrl", "\"http://43.255.39.52/\""
            manifestPlaceholders = [AMAP_KEY: "62d92d8557a59aeaf077b895b87ed338", allowBackup: "true"]
            minifyEnabled false//是否混淆
            shrinkResources false
            zipAlignEnabled true //对齐操作，使得我们的程序在Android系统中运行得更快
            proguardFiles getDefaultProguardFile('proguard-android.txt'), PROGUARD_RULES
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            renderscript.srcDirs = ['src']
            aidl.srcDirs = ['src']
            res.srcDirs = ['src/main/res', 'src/main/res-chatroom', 'src/main/res-rp']
            jniLibs.srcDirs = ['libs', 'libs-sdk']
            assets.srcDirs = ['src/main/assets']
        }
    }
    lintOptions {
        abortOnError false
        checkReleaseBuilds false
        disable 'GoogleAppIndexingWarning'
        // 防止在发布的时候出现因MissingTranslation导致Build Failed!
//        disable 'MissingTranslation'
    }
    dexOptions {
        preDexLibraries false
        jumboMode true
        javaMaxHeapSize "4g"
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/INDEX.LIST'
    }
    aaptOptions {
        cruncherEnabled = false
        useNewCruncher = false
    }

    flavorDimensions "rc"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

//拷贝APK文件到指定文件夹
task copyAPK(type: Copy) {
    include '**/*.apk'
    from '/build/outputs/apk'
    into '../APK/'
}

//在task被添加的时候定义依赖关系，copyApk任务总是在打包完成后执行
tasks.whenTaskAdded {
    task ->
        if (task.name.startsWith("assemble") && task.name.endsWith('Release')) {
            task.finalizedBy copyAPK
        }
}