Hi, I'm getting a `NoSuchMethodError` on an method...
# android
d
Hi, I'm getting a
NoSuchMethodError
on an method that I defined. I recently updated the project to Kotlin 2.2.0, so maybe some dependency needs updating as well, but it's weird since the method is one I defined and not coming from any library. Full error in thread.
Copy code
java.lang.NoSuchMethodError: No static method minus-HG0u8IE(Lkotlinx/datetime/LocalTime;J)Lkotlinx/datetime/LocalTime; in class Lcom/tavosleep/app/core/domain/LocalDateTimeExtKt; or its super classes (declaration of 'com.tavosleep.app.core.domain.LocalDateTimeExtKt' appears in /data/data/com.tavosleep.app/code_cache/.overlay/base.apk/classes16.dex)
                                                                                                    	at com.tavosleep.app.core.domain.SleepTime.<init>(SleepTime.kt:15)
                                                                                                    	at com.tavosleep.app.core.domain.SleepTime.<init>(Unknown Source:0)
                                                                                                    	at com.tavosleep.app.core.domain.SleepTimeKt.fromPackedInt(SleepTime.kt:65)
                                                                                                    	at com.tavosleep.app.device.tavo.MetaWearDeviceAdapter.readAlarmState(MetaWearDeviceAdapter.kt:181)
                                                                                                    	at com.tavosleep.app.device.tavo.MetaWearDeviceAdapter$readAlarmState$1.invokeSuspend(Unknown Source:14)
                                                                                                    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                    	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:995)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:103)
                                                                                                    	at android.os.Looper.dispatchMessage(Looper.java:315)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:251)
                                                                                                    	at android.os.Looper.loop(Looper.java:349)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:9200)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:929)
                                                                                                    	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@a7cd8e0, Dispatchers.Main.immediate]
c
can you show the definition?
d
Copy code
operator fun LocalTime.minus(duration: Duration): LocalTime {
    val dayNanos = 24L * 60 * 60 * 1_000_000_000L
    val delta = duration.inWholeNanoseconds
    val nowNanos = ((hour * 3600L + minute * 60L + second) * 1_000_000_000L) + nanosecond
    val newNanos = ((nowNanos - delta) % dayNanos + dayNanos) % dayNanos

    val newHour       = (newNanos / 3_600_000_000_000L).toInt()
    val leftover1     = newNanos % 3_600_000_000_000L
    val newMinute     = (leftover1 /   60_000_000_000L).toInt()
    val leftover2     = leftover1 %   60_000_000_000L
    val newSecond     = (leftover2 /    1_000_000_000L).toInt()
    val newNanosecond = (leftover2 %    1_000_000_000L).toInt()

    return LocalTime(newHour, newMinute, newSecond, newNanosecond)
}
a
IDK how related it is, but you are using Kotlinx datetime. That lib removed some stuff because its now in the kotlin time standard library. If a dependency compiled against an earlier version 0.6.1, IIRC, and you pull in 0.7.0, the dep cant find the method in the new version. So you get an error very similar to what you are seeing. I moved all my deps up and ported them to use kotlin.time...
☝️ 2
d
Could be, but would that explain why if I copy the function from the common source set to the android one, it finds the method...