I'm getting java.lang.NoClassDefFoundError
on a Android app. I managed to isolate the issue to a call to List::replaceAll. The problem is that method is for Java 8 and is not available in some devices, and Kotlin/Gradle is compiling it successfully.
Similar issue: java.lang.NoClassDefFoundError $$inlined$forEach$lambda$1 in Kotlin
My question is. Is there a way to give me a compilation error any time I use Java 8 SDK in my project? I've tried to manually set Java 1.7 like below, but the code with Java 8 compiles successfully.
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
sourceCompatibility = JavaVersion.VERSION_1_7 // Is it even relevant here?
targetCompatibility = JavaVersion.VERSION_1_7
kotlinOptions {
jvmTarget = "1.6"
}
}
Also important, the code is not in a Android module. My Android module doesn't let me use that method, as expected.