https://kotlinlang.org logo
e

Ewan

11/12/2020, 3:40 PM
I have an Android project in AndroidStudio 4.2 Canary 16 which has a dependency on an external Kotlin library locally published to maven (written in Idea 2020.2). Both project and library use Kotlin 1.4.10 and the new backend compiler. The problem I have is that I'm able to execute Android code which refers to objects from the Kotlin library but cannot access the objects directly during debugging via breakpoints or using Evaluate Expression. For example given library class
class Person(val name: String) {
fun greeting() = "Hello, I'm $name"
}
I can run this test in Android Studio:
class ExampleUnitTest {
@Test
fun name() {
val person = Person("Jane")
assert(person.name == "Jane")
}
}
but... If I set a non-suspending breakpoint to print out the value of person.name or a set a suspending breakpoint and use Evaluate Expression to evaluate person.name I get the error: Class 'uk.co.telesense.controller.Person' is compiled by a new Kotlin compiler backend and cannot be loaded by the old compiler If I debug the test with no breakpoints it runs green. Any idea what's going on here? In the kotlin library I have:
compileKotlin {
kotlinOptions.useIR = true
}
compileTestKotlin {
kotlinOptions.useIR = true
}
in the Android Studio project I have
buildscript {
ext.kotlin_version = '1.4.10'
...
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-alpha15'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
...
}
I hope that makes sense! Any ideas?
z

Zach Klippenstein (he/him) [MOD]

11/12/2020, 3:56 PM
I think Android Studio doesn't fully support the IR compiler yet (I've seen responses to that effect on this slack in the past). Not sure when that will be fixed, might be better to ask in #android-studio though
e

Ewan

11/12/2020, 5:06 PM
Thanks, that make sense. I'll try over there
3 Views