import org.json.JSONObject

apply plugin: 'com.android.application'
apply plugin: "androidx.navigation.safeargs"


// 获取最新版本名称和版本号
def newVersion = new JSONObject(file('../version_info.json').text).optJSONArray("info").getJSONObject(0)
def vName = newVersion.optString("versionName")
def vCode = newVersion.optLong("versionCode")
println vName
println vCode

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "com.unis.sxzcl"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode vCode.toInteger()
        versionName vName
        ndk {
            //设置支持的SO库架构
            abiFilters 'armeabi-v7a' //,'x86', 'x86_64', 'arm64-v8a'
        }
        multiDexEnabled true

        flavorDimensions "channel"
    }

    // view绑定
    viewBinding {
        enabled = true
    }

    // 签名配置
    signingConfigs {
        release {
            v1SigningEnabled true
            v2SigningEnabled true

            storeFile file(KEY_PATH)
            storePassword KEY_PWD
            keyAlias = ALIAS_NAME
            keyPassword ALIAS_PWD
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            zipAlignEnabled = true
        }
        debug {
            signingConfig signingConfigs.release
        }
    }
    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    //配置自定义打包名称和位置
    android.applicationVariants.all { variant ->
        // 将apk文件输出到 /apk/release 或 /apk/debug
        if (variant.buildType.name.equals('release')) {
            variant.getPackageApplicationProvider().get().outputDirectory = new File("../apk/" + variant.buildType.name)
        }
        variant.outputs.all { output ->
            def date = new Date().format("yyyyMMddHHmm")
            def versionName = defaultConfig.versionName
            def versionCode = defaultConfig.versionCode
            def buildType = variant.buildType.name

            // 输出的apk名称
            // sxzcl_release_x.x_x.apk
            outputFileName = "sxzcl_${buildType}_${versionName}_${versionCode}.apk"
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.android.support:design:28.0.3'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.google.android:flexbox:2.0.1'
    implementation 'com.android.support:multidex:1.0.3'

    api project(path: ':icon')
    api project(path: ':model')

    //状态栏框架
    implementation 'com.jaeger.statusbarutil:library:1.5.1'
    //图片压缩
    implementation 'com.github.nanchen2251:CompressHelper:1.0.5'
    //轮播图
    implementation 'com.youth.banner:banner:2.1.0'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    //图表库
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.2'
    implementation 'androidx.navigation:navigation-ui:2.3.2'
}