I saw the issue #2041 but looks like my issue is a different.
App works fine with version 1.3.6 and crashes on 1.3.7
With 1.3.7 app crashes on start.
Crashlog:
java.lang.VerifyError: Verifier rejected class com.volcast.data.VolcastRepositoryImpl: java.lang.Object com.volcast.data.VolcastRepositoryImpl.refresh(kotlin.coroutines.Continuation) failed to verify: java.lang.Object com.volcast.data.VolcastRepositoryImpl.refresh(kotlin.coroutines.Continuation): [0x12F] register v3 has type Reference: java.lang.Exception but expected Precise Reference: kotlin.jvm.internal.Ref$ObjectRef (declaration of 'com.volcast.data.VolcastRepositoryImpl' appears in /data/app/com.volcast.temp-6UrzwdYgEJRIKC9aa-RzVQ==/base.apk!classes2.dex)
at com.volcast.di.DataModuleKt$dataModule$1$12.invoke(DataModule.kt:58)
at com.volcast.di.DataModuleKt$dataModule$1$12.invoke(Unknown Source:4)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:50)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:36)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:87)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:214)
at org.koin.core.scope.Scope.get(Scope.kt:181)
at com.volcast.di.ViewModelModuleKt$viewModelModule$1$7.invoke(ViewModelModule.kt:72)
at com.volcast.di.ViewModelModuleKt$viewModelModule$1$7.invoke(Unknown Source:4)
...
code:
interface VolcastRepository {
fun getVolcasts(): LiveData<ModelEvent<List<Volcast>>>
suspend fun refresh()
}
class VolcastRepositoryImpl(
private val volcastDao: VolcastDao,
private val api: Api,
private val mapperVolcastRemoteDb: MapperVolcastRemoteDb,
mapperVolcastDbApp: MapperVolcastDbApp,
private val dispatchersManager: DispatchersManager
) : VolcastRepository {
private val _networkState = MutableLiveData<ModelEvent<Nothing>>()
private val _volcast = RemoteLiveData(
dbData = volcastDao.getVolcasts(),
remoteState = _networkState,
mapper = mapperVolcastDbApp
)
override fun getVolcasts(): LiveData<ModelEvent<List<Volcast>>> = _volcast
override suspend fun refresh() {
if (_networkState.value is ModelEvent.Start)
return
withContext(dispatchersManager.ui) {
_networkState.value = ModelEvent.Start()
}
try {
val volcasts = withContext(dispatchersManager.io) {
api.getVolcasts()
}
withContext(dispatchersManager.default) {
volcastDao.updateVolcasts(volcasts.volcasts?.map { mapperVolcastRemoteDb.map(it) })
}
withContext(dispatchersManager.ui) {
_networkState.value = ModelEvent.Complete()
}
} catch (e: Exception) {
withContext(dispatchersManager.ui) {
_networkState.value = ModelEvent.Error(e.toAppException())
}
}
}
}
If i remove try and catch - app starts ok but without crash handling.
Moving all code inside "try-catch" to the another function didn't help.
Could you please specify your Kotlin version?
As a workaround, please extract withContext (probably from catch block) to a separate function.
Unfortunately, if I'm watering down your example, the bug won't reproduce, so if you could simplify it a bit, it would be really great
@qwwdfsad I moved all withContext from try and catch blocks to other functions and it helped me. App works as expected now.
Great!
Unfortunately, this is a compiler bug that will only be fixed in Kotlin 1.4 (https://youtrack.jetbrains.com/issue/KT-39113), so we cannot fix it right now
Thank you for your help. Should i close the issue or you will do it yourself?
revert coroutines lib to 1.3.6 works for me
Great!
Unfortunately, this is a compiler bug that will only be fixed in Kotlin 1.4 (https://youtrack.jetbrains.com/issue/KT-39113), so we cannot fix it right now
Yeah, this has resolved for me by upgrading to Kotlin 1.4.10.
Most helpful comment
revert coroutines lib to 1.3.6 works for me