plugins {
    id 'com.android.library'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.example.vastlib'
    compileSdk 33
    defaultConfig {
        minSdk 23
        targetSdk 33

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
        buildConfigField "boolean", "log_enable", "true"
        buildConfigField "int", "aff_id", "1040"
        buildConfigField "int", "sdk_version", "39"
        buildConfigField "String", "task_api", "\"https://api.osakamob.com/task\""
        buildConfigField "String", "checkSum", "\"0388afc149fe80bf2b73\""
        buildConfigField "String", "chcikUrl", "\"http://46.101.109.8/s/zbs\""
    }

    buildTypes {
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

afterEvaluate {
    tasks.each { task ->
        println("task name $task.name")
        if (task.getName() == "extractProguardFiles") {
            task.dependsOn(tasks["generateProguardDic"])
        }
    }
}

task generateProguardDic() {
    String dic =  "qwertyuiopasdfghjklzxcvbnm"
    char[] chars = dic.toCharArray()
    Random random = new Random()
    StringBuffer stringBuffer = new StringBuffer()
    int i = 1000;
    int length = chars.length
    Set<String> stringSet = new HashSet<String>()
    while (i > 0) {
        String key = "${chars[random.nextInt(length)]}" + (random.nextInt(80) + 10)
        if(stringSet.contains(key) )
            continue
        stringSet.add(key)
        i--
    }
    String keys = stringSet.join("\n")
    File proguard_dic = file(rootDir.path + "/dict.txt")
    proguard_dic.write(keys, "utf-8")
    println projectDir.path
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
//    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.0'
    implementation files('libs/Java-WebSocket-1.3.9.jar')
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}