본문 바로가기
[coroutine] java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android' -coroutine 을 사용한 project 에서 release build (minify 포함) 을 하면 아래와 같은 exception 이 발생하며 crash 가 발생한다.java.lang.IllegalStateException: Module with the Main dispatcher is missing. Add dependency providing the Main dispatcher, e.g. 'kotlinx-coroutines-android’ -범인은 바로 proguard.proguard 파일은 version 에 따라 바뀔지 모르지만, 아래 링크를 참조하면 최신정보를 계속 얻을 수 있지 않을까 싶다. https://github.com/Kotlin/kotlinx.coroutines/blob/maste.. 2020. 8. 16.
[Kotlin] check lateinit is initialized (safely accessing lateinit vars) https://blog.jetbrains.com/kotlin/2017/09/kotlin-1-2-beta-is-out/ -Exception in thread "main" kotlin.UninitializedPropertyAccessException 위의 exception 을 마딱뜨린 사람이 은근 많을 것이다.그렇다 저 녀석은 lateinit 이라고 선언된 var 에 값이 assign 되기 전에 접근할 때 생기는 exception 이다. -Kotlin 1.2 에서 추가된 기능이 있는데, 바로 reflection 방식을 이용한 isInitialized 함수이다.lateinit var file:File // ... if (::file.isInitialized) { ... } -reflection 방식이기 때문에.. 2020. 8. 12.
[Kotlin] Kotlin 으로 build gradle 을 작성하자! https://proandroiddev.com/migrating-android-app-to-gradle-kotlin-dsl-1-0-c903760275a5 -gradle 4.9 이상 버전부터 사용 가능하다.Kotlin DSL 은 gradle build script 를 지원하는 kotlin 언어이다.( 기존에 우리가 쓰던 것은 groovy ) -Kotlin DSL 은 groovy 방식에 비해 IDE 에서 제공하는 다음의 기능들을 함께 제공한다. Auto-completionContent assistQuick documentationNavigation to source codeRefactoring and much more -android studio 도 최신 버전을 사용하는 것이 추천된다. -kts 는 Grad.. 2020. 8. 10.
[kotlin] safe when statement http://blog.karumi.com/kotlin-android-development-6-months-into-it/ - when 을 expression 으로 사용될 때에는 cover 하지 않는 케이스에 대한 else 가 꼭 필요하다. 하지만 statement 로 사용될 때에는 꼭 쓰지 않아도 괜찮다. (강요되지 않는다.) 이 때문에 모든 case 를 커버하는지 알 수 없었다. 아래와 같이 Any? 에 대한 extension 으로 exhaustive 를 줌으로써 expression 처럼 쓰도록 하여 에러를 줄일 수 있다. val Any?.exhaustive get() = Unit private fun onStatusChanged(status:Status){ when(status){ is Status... 2020. 8. 9.
[kotlin] Sealed class 를 이용하여 error 를 다루는 방법 https://articles.caster.io/android/handling-optional-errors-using-kotlin-sealed-classes/ - private fun parse(url:String): ParsedData{ val result = URL_PARSE_REGEX.find(url) if( result == null){ // what to do here? } val mimeType = result.groupValues[2] val data = result.groupValues[4] return ParsedData(data, mimeType) } data class ParsedData(val data:String, val mimeType:String) 위와 같은 코드가 있다. - .. 2020. 8. 8.
[Kotlin] Coroutine 에 대한 이해 : 기본 용어 및 사용 https://android.jlelse.eu/coroutines-basic-terminologies-and-usage-b4242bd1b2a4 Coroutine 이 뭐냐? -Coroutine 은 suspendable computaion instance 이다.코드 블럭이 life-cycle 을 가지고 생성되고 수행된다는 것이 개념상 thread 와 비슷하지만, 특정 thread 에 bound 되어 있지 않다.한 thread 에서 실행되고, 다른 thread 에서 resume 될 수도 있다.future 와 같이 result 나 exception 으로 종료될 수 있다. -Coroutine 은 lightweight thread 라고 볼 수 있다.여러개의 function 을 async 로 호출할 수 있고, 더 짧.. 2020. 8. 7.
[Koin] Koin 에 대해 알아보자 (tutorial) https://www.raywenderlich.com/9457-dependency-injection-with-koin Using Kotlin to Simplify DI - Koin 을 써야 하는 이유는 무엇일까? Koin 은 더 꽉 들어맞고, 더 직관적으로 쓸 수 있다. Dagger2 를 예로 들어보면, Dagger2 는 먼저 module, component, 그리고 inject annotation 들의 개념에 익숙해져야 한다. learning curve 는 매우 비싸다. (배우기가 어렵다는 이야기) 이 외에도 scope, subcomponent 들에 대한 추가 학습도 필요하다. 반대로, Koin 은 단순히 module 만 정의하면 된다. Koin Basics Koin 을 사용하기 위해서는 3가지 단계만.. 2020. 8. 6.
[kotlin] crossinline 에 대해 알아보자. - 코드를 보다보니 이런 녀석을 보았다. inline fun TextView.addTextChangedListener( crossinline beforeTextChanged: ( text: CharSequence?, start: Int, count: Int, after: Int ) -> Unit = { _, _, _, _ -> }, crossinline onTextChanged: ( text: CharSequence?, start: Int, count: Int, after: Int ) -> Unit = { _, _, _, _ -> }, crossinline afterTextChanged: (text: Editable?) -> Unit = {} ): TextWatcher { val textWatcher =.. 2020. 8. 5.
[coroutine] Shared mutable state and concurrency [coroutine] Shared mutable state and concurrency https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/shared-mutable-state-and-concurrency.md#shared-mutable-state-and-concurrency -Dispatchers.Default 와 같은 dispatcher 를 사용하여 coroutine 은 multi thread 에서 병렬적으로 수행될 수 있다.이는 일반적인 병렬 관련 문제를 보여준다.주요 문제는 공유된 변경가능한 상태에 대한 동기화이다. The problem -suspend fun massiveRun(action : suspend () -> Unit){ val.. 2020. 3. 13.
반응형