Kotlin 버전 vs AndroidX Lifecycle 라이브러리 간의 호환성 문제

lint 검사에서 NullSafeMutableLiveData 관련 문제로 앱 release 빌드가 되지 않는 문제가 발생하여 관련 lint 검사를 끄는 방식으로 우회하였다.

kotlin = “2.1.20” vs androidxLifecycle = “2.9.0”

새로 만든 앱을 출시하기 위해서 처음으로 release 빌드 명령을 내려보았다. 컴파일 오류가 생겼다. 처음에는 역시나 proguard 문제로 중단됐고, 그걸 해결하고 난 후에 다음의 오류가 생겼다.

Unexpected failure during lint analysis (this is a bug in lint or one of the libraries it depends on)

Message: Unexpected failure during lint analysis (this is a bug in lint or one of the libraries it depends on)

Message: Unexpected failure during lint analysis of Functions.kt (this is a bug in lint or one of the libraries it depends on)

Message: Found class org.jetbrains.kotlin.analysis.api.resolution.KaCallableMemberCall, but interface was expected

The crash seems to involve the detector \\\`androidx.lifecycle.lint.NonNullableMutableLiveDataDetector\\\`.
You can try disabling it with something like this:
android {
lint {
disable "NullSafeMutableLiveData"
}
}

Stack: \\\`IncompatibleClassChangeError:NonNullableMutableLiveDataDetector$createUastHandler$1.visitCallExpression(NonNullableMutableLiveDataDetector.kt:140)←UElementVisitor$DispatchUastVisitor.visitCallExpression(UElementVisitor.kt:412)←UElementVisitor$DelegatingUastVisitor.visitCallExpression(UElementVisitor.kt:756)←

[후략]

해결

실패한 방법

린크 검사를 통과하지 못해서 컴파일이 되지 못하는 상황이다. 위의 오류 메시지에도 해결법이 추천되어 있다. 그게 Goovy 문법으로 돼 있으니까 Kotlin DSL 코드로 바꾸어서 android 블록이 다음과 같이 되도록 해보았다:

module build.gradle.kts:

android {
//...

lint {
disable.add("NullSafeMutableLiveData")
}

//...
}

하지만 아쉽게도 이 방법으로는 문제가 해결되지 않았다.

성공한 방법

나중에 알고 보니, 앱 모듈보다는 라이브러리 모듈이 문제였던 것 같다. 이 프로젝트는 멀티 모듈 체제로 돼 있는데 lint 검사 문제가 myLibrary 모듈에서 발생한 것으로 보인다.

다음과 같이 프로젝트 전체에서 NullSafeMutableLiveData 검사를 꺼서 컴파일 오류 문제가 해결되었다.

root build.gradle.kts:

subprojects {
plugins.withId("com.android.application") {

// ApplicationExtension = AGP 8.x. 7.x라면 BaseAppModuleExtension 사용.
extensions.configure<com.android.build.api.dsl.ApplicationExtension> {

//...

// Disable problematic lint check that's causing build failures
lint {
disable.add("NullSafeMutableLiveData")
}
}
}

// Also apply to library modules
plugins.withId("com.android.library") {
extensions.configure<com.android.build.api.dsl.LibraryExtension> {
lint {
disable.add("NullSafeMutableLiveData")
}
}
}
}

사실 난 liveData 를 명시적으로 사용하지는 않아서 이렇게 해도 상관없었다.

그러나 이 방법이 근본적인 해결책이라고는 할 수 없고, 나중에 kotlin 또는 androidxLifecycle 을 차기 버전으로 업데이트 하면 제대로 해결될 거로 기대한다.

Leave a Comment