plugins {
    id 'com.android.application'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.wisewoods.eduandroid"
        minSdk 24
        targetSdk 28
        versionCode getMyAppVersionCode()
        versionName getMyAppVersionName()
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        buildFeatures {
            viewBinding = true
        }
        ndk {
            abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
        }
        manifestPlaceholders = [
                XG_ACCESS_ID : "1500026199",
                XG_ACCESS_KEY: "A2IFX1S0GQVY",
        ]
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    // 设置发布版的签名
    signingConfigs {
        debug {
            storeFile file('./eduandroid.jks')
            keyAlias 'eduandroid'
            storePassword 'eduandroid'
            keyPassword 'eduandroid'

        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    packagingOptions {
        pickFirst '**/libc++_shared.so'
        doNotStrip "*/armeabi/libYTCommon.so"
        doNotStrip "*/armeabi-v7a/libYTCommon.so"
        doNotStrip "*/x86/libYTCommon.so"
        doNotStrip "*/arm64-v8a/libYTCommon.so"
    }
}

dependencies {

    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
    implementation project(path: ':base')
    implementation project(path: ':meeting')
    implementation project(path: ':live')

    implementation 'androidx.camera:camera-camera2:1.1.0-beta02'
    implementation 'androidx.camera:camera-lifecycle:1.1.0-beta02'
    implementation 'androidx.camera:camera-view:1.1.0-beta02'
    implementation 'androidx.camera:camera-core:1.1.0-beta02'

    implementation 'com.github.azhon:AppUpdate:3.0.5'
    implementation 'com.qcloud.cos:cos-android:5.7.3'
    implementation 'com.tencent.tpns:tpns:1.2.7.1-release'

    implementation 'com.pgyer:analytics:4.2.0'

    implementation 'xyz.doikki.android.dkplayer:dkplayer-java:3.3.5'
    implementation 'xyz.doikki.android.dkplayer:dkplayer-ui:3.3.5'
    implementation 'xyz.doikki.android.dkplayer:videocache:3.3.5'

    implementation 'com.google.android.flexbox:flexbox:3.0.0'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

task updateVersionCode(){
    doFirst{
        // 获取 gradle.properties 文件
        def gradleProperties = file('../version.properties')
        // 读取里面的键值对
        def properties = new Properties()
        properties.load(new FileInputStream(gradleProperties))
        // 获取里面的 APP_VERSION_CODE 进行 +1
        def codeBumped = properties['APP_VERSION_CODE'].toInteger() + 1
        // 重新赋值
        properties['APP_VERSION_CODE'] = codeBumped.toString()
        // 写入
        properties.store(gradleProperties.newWriter(), null)
    }
}

project.tasks.whenTaskAdded { Task theTask ->
    if (theTask.name == 'assembleRelease' || theTask.name == 'assembleDebug') {
        theTask.dependsOn(updateVersionCode)
        theTask.mustRunAfter(updateVersionCode)				// updateVersionCode在assembleRelease之前执行
    }
}

//preBuild.dependsOn(updateVersionCode)


def getMyAppVersionCode() {  //获取APP版本号
    def gradleProperties = file('../version.properties')
    def properties = new Properties()
    properties.load(new FileInputStream(gradleProperties))
    def codeBumped = properties['APP_VERSION_CODE'].toInteger() + 1
    return codeBumped as int
}


def getMyAppVersionName() {  //获取APP版本号
    def gradleProperties = file('../version.properties')
    def properties = new Properties()
    properties.load(new FileInputStream(gradleProperties))
    def codeBumped = properties['APP_VERSION_CODE'].toInteger() + 1
    return "1.0."+codeBumped
}
