Home > other >  How to read and parse .json file in gradle.kts?
How to read and parse .json file in gradle.kts?

Time:05-27

my json is

{"enable": true}

place under asset folder in android studio

so I need to get that value and use it inside build.gradle.kts

CodePudding user response:

gradle.buildFinished {
try {
    val file = File("app/src/main/assets/soundEnable.json")
    val json = groovy.json.JsonSlurper().parseText(file.readText()) as Map<String, String>
    if (json["enable"] as Boolean) {
        //do something
    }
} catch (ignore: Throwable) {
    println("=======")
    println(ignore.localizedMessage)
    println(ignore.cause)
    println(ignore.stackTrace)
    println("=======")
}

}

  • Related