Is it possible to set jvmTarget = "1.8"
only for unit tests in gradle for an Android app? I was using:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
But then I got crashes on older 4.4 devices...
Yes, you can do that simply by setting jvmTarget
for a certain Kotlin compilation task.
In an Android project, the unit tests are normally compiled by the tasks compileDebugUnitTestKotlin
, compileReleaseUnitTestKotlin
etc. You may find the complete list of Gradle tasks in the IDE's Gradle view or by running:
./gradlew tasks --all
Search for the names following the pattern compile*Kotlin
.
Then just configure the single task that you need, for example:
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile)
.matching { it.name == "compileDebugUnitTestKotlin" }
.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.