본문 바로가기
Android/안드로이드 스터디(Kotlin)

Android, Kotlin 오류] java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'

by 김마리님 2022. 5. 12.

한줄 요약 : 코루틴 종속을 추가하면 된다. (아랫줄에 추가 코드 있음!)

 

 

 

구글 플레이 인앱 결제를 무작정 따라하다가, 코루틴 suspend 문법을 만났다. 코루틴이 필수인 것 처럼 보인다 -_- 하긴 결제 스레드 처리하려면 맞는거 같기도 하다. 

 

일시 중지 suspend method의 경우 무조건 코루틴 함수 내부에서 돌려야만 하는데, 그래서 무작정 CoroutineScope(Dispatchers.Main).launch 를 사용했더니

 

java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' and ensure it has the same version as 'kotlinx-coroutines-core'

 

짜잔. 다음과 같은 오류를 투척했다.

난 코루틴 확장을 지원한다길래 해당 종속성을 추가하면 코루틴까지 자동으로 추가해줄줄 알았는데 아니었나보다 -_-

 

그런고로  종속을 추가해주면 된다.

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
반응형