0

I'am trying to parse json file in gradle task using JsonSlurper in a Android project, but the Android Studio prompt that "Cannot resolve symbol 'JsonSlurper'".

My question is since gradle is based on groovy,it shuld be able to use groovy APIs like JsonSlurper in it, why Android Studio din't recognize the groovy.json.JsonSlurper(), I searched several answers here, How to read a json file into build.gradle and use the values the strings in build.gradle file and groovy.json.JsonSlurper parse JSON The answers also reommend using JsonSlurper, how they achieve that?

My Android Studio Version is 3.4, gradle version is gradle-4.10.1, here is the content of my gradle file:

ext {
    destPath = project.rootDir.getAbsolutePath() + "/output/"
    configPath = project.rootDir.getAbsolutePath() + "/script/"
}

task myClean(type: Delete) {
    delete(destPath)
}
task minifyTask(dependsOn: myClean) << {
    def configFile = new File(configPath + 'config.cfg')
    ddef parsedJson = new groovy.json.JsonSlurper().parseText(configFile.text)

}

I expect to use JsonSlurper to parse json file in gradle file normally

ayutan
  • 98
  • 8

0 Answers0