Search code examples
androidgradlekotlingradle-kotlin-dsl

Gradle Kotlin DSL can't find java.io package


I'm trying to convert the build.gradle file of an Android app to a Kotlin DSL. This file has a function like this:

def getLastCommitHash() {
    def stdout = new ByteArrayOutputStream()
    exec {
        commandLine 'git', 'rev-parse', '--short', 'HEAD'
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

which I converted to this:

fun getLastCommitHash() {
    val stdout = ByteArrayOutputStream()
    exec {
        commandLine("git", "rev-parse", "--short", "HEAD")
        standardOutput = stdout
    }
    return stdout.toString().trim()
}

I get an Unresolved reference: ByteArrayOutputStream error and applying the import which changes it to java.io.ByteArrayOutputStream() shows an Unresolved reference: io error.

Is there something I'm doing wrong? Thanks in advance.


Solution

  • This was an issue with Android Studio 3.5.6. After upgrading to Android Studio 3.6 everything is working.