apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    def currentVersionCode = getVersionCode()
    def currentVersionName = getVersionName()

    defaultConfig {
        applicationId "com.bearya.kids"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode currentVersionCode
        versionName currentVersionName
        multiDexEnabled true
        vectorDrawables.useSupportLibrary true
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString(),
                             "room.expandProjection":"true"]
            }
        }
    }

    dataBinding {
        enabled true
    }

    aaptOptions {
        noCompress "webp"  //表示不让aapt压缩的文件后缀
    }

    signingConfigs {
        config {
            keyAlias 'BeiYa'
            storePassword 'BeiYa123'
            storeFile file('../bearya_keystore.jks')
            keyPassword 'BeiYa!@#'
        }
    }

    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
            buildConfigField "String", "BuglyAppKey", BUGLY_APP_KEY
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            debuggable false
            minifyEnabled false
            buildConfigField "String", "BuglyAppKey", BUGLY_APP_KEY
            signingConfig signingConfigs.config
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            if ("release" == buildType.name)
                output.outputFileName = "Kids_${defaultConfig.versionCode}_v${defaultConfig.versionName}_release.apk"
            else
                output.outputFileName = "Kids_v${defaultConfig.versionName}.apk"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = 1.8
    }


}

kapt {
    generateStubs = true
}

// 获取版本号
def getVersionCode() {
    def versionFile = file('version.properties')// 读取第一步新建的文件
    if (versionFile.canRead()) {// 判断文件读取异常
        Properties versionProps = new Properties()
        versionProps.load(new FileInputStream(versionFile))
        def versionCode = versionProps['VERSION_CODE'].toInteger()// 读取文件里面的版本号
        versionProps['VERSION_CODE'] = (++versionCode).toString()
        versionProps.store(versionFile.newWriter(), null)
        return versionCode // 返回自增之后的版本号
    } else {
        throw new Exception("Could not find version.properties!")
    }
}

def getVersionName() {
    def versionFile = file('version.properties')// 读取第一步新建的文件
    if (versionFile.canRead()) {// 判断文件读取异常
        Properties versionProps = new Properties()
        versionProps.load(new FileInputStream(versionFile))
        def versionName = versionProps['VERSION_NAME'].toString()// 读取文件里面的版本号
        return versionName // 返回版本
    } else {
        throw new Exception("Could not find version.properties!")
    }
}


dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.viewpager2:viewpager2:1.0.0'
    implementation 'androidx.paging:paging-runtime:2.1.2'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
    implementation 'androidx.lifecycle:lifecycle-reactivestreams:2.2.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0-alpha05'
    implementation 'androidx.navigation:navigation-ui-ktx:2.3.0-alpha05'
    implementation 'androidx.room:room-runtime:2.2.5'
    implementation 'androidx.room:room-ktx:2.2.5'
    implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
    implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.viewpager2:viewpager2:1.0.0'

    implementation 'com.google.code.gson:gson:2.8.6'

    implementation 'com.tencent.bugly:nativecrashreport:3.7.1'
    implementation 'com.tencent.tinker:tinker-android-lib:1.9.14.5'
    implementation 'com.tencent.bugly:crashreport_upgrade:1.4.5'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    implementation 'com.github.SheHuan:NiceImageView:1.0.5'
    implementation 'jp.wasabeef:glide-transformations:4.0.1'
    implementation 'com.orhanobut:logger:2.2.0'
    implementation 'com.kaopiz:kprogresshud:1.2.0'

    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    kapt 'androidx.annotation:annotation:1.1.0'
    kapt 'androidx.room:room-compiler:2.2.5'
}
