Binding이 되지않을때 (by viewModels()에 에러)
프로젝트가 세팅되지 않은 상태에서 디펜던시 정의를 빠트린경우인데 new Project를 통해 empty activity 프로젝트로 시작하면 항상 빠트리다 보니 포스팅으로 정리해둡니다.
by viewModels()에 에러가 나는 경우.
프로젝트가 세팅되지 않은 상태에서 디펜던시 정의를 빠트린경우인데 new Project를 통해 empty activity 프로젝트로 시작하면 항상 빠트리다 보니 포스팅으로 정리해둡니다.
val viewModels : ViewModelClass by viewModels()
Unresolved reference: viewModels
by 키워드를 이용한 위임으로 처리되는데 이 확장함수는 activity-ktx나 fragment-ktx에 정의 되어있습니다.
dependencies{
implementation 'androidx.activity:activity-ktx:1.2.0'
or
implementation 'androidx.fragment:fragment-ktx:1.3.0'
}
참고로 fragment-ktx가 activity-ktx에 의존성을 가지고 있습니다. (아래의 트리는 보기 편하게 적절하게 편집했습니다.)
androidx.activity:activity-ktx:1.2.0 의존성 그래프
+--- androidx.activity:activity-ktx:1.2.0
+--- androidx.activity:activity:1.2.0
+--- androidx.annotation:annotation:1.1.0
+--- androidx.core:core:1.1.0 -> 1.3.2 (*)
+--- androidx.lifecycle:lifecycle-runtime:2.3.0 (*)
+--- androidx.lifecycle:lifecycle-viewmodel:2.3.0
+--- androidx.savedstate:savedstate:1.1.0
\--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0
+--- androidx.annotation:annotation:1.0.0 -> 1.1.0
+--- androidx.savedstate:savedstate:1.1.0 (*)
+--- androidx.lifecycle:lifecycle-livedata-core:2.3.0
| \--- androidx.lifecycle:lifecycle-common:2.3.0 (*)
\--- androidx.lifecycle:lifecycle-viewmodel:2.3.0 (*)
androidx.fragment:fragment-ktx:1.3.0 의존성 그래프
+--- androidx.fragment:fragment-ktx:1.3.0
+--- androidx.activity:activity-ktx:1.2.0
| +--- androidx.activity:activity:1.2.0 (*)
| +--- androidx.core:core-ktx:1.1.0 -> 1.3.2 (*)
| +--- androidx.lifecycle:lifecycle-runtime-ktx:2.3.0
| +--- androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0
| | +--- androidx.lifecycle:lifecycle-viewmodel:2.3.0 (*)
| | +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.20 -> 1.4.30 (*)
| | \--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1 (*)
| +--- androidx.savedstate:savedstate-ktx:1.1.0
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.20 -> 1.4.30 (*)
+--- androidx.fragment:fragment:1.3.0
| +--- androidx.annotation:annotation:1.1.0
| +--- androidx.core:core:1.1.0 -> 1.3.2 (*)
| +--- androidx.collection:collection:1.1.0 (*)
| +--- androidx.viewpager:viewpager:1.0.0
| +--- androidx.loader:loader:1.0.0
| | +--- androidx.lifecycle:lifecycle-livedata:2.0.0 -> 2.2.0
| | \--- androidx.lifecycle:lifecycle-viewmodel:2.0.0 -> 2.3.0
| +--- androidx.activity:activity:1.2.0
| | +--- androidx.annotation:annotation:1.1.0
| | +--- androidx.core:core:1.1.0 -> 1.3.2 (*)
| | +--- androidx.lifecycle:lifecycle-runtime:2.3.0 (*)
| | +--- androidx.lifecycle:lifecycle-viewmodel:2.3.0 (*)
| | +--- androidx.savedstate:savedstate:1.1.0
| | \--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0
| +--- androidx.lifecycle:lifecycle-livedata-core:2.3.0 (*)
| +--- androidx.lifecycle:lifecycle-viewmodel:2.3.0 (*)
| +--- androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.0 (*)
| +--- androidx.savedstate:savedstate:1.1.0 (*)
| \--- androidx.annotation:annotation-experimental:1.0.0
+--- androidx.core:core-ktx:1.1.0 -> 1.3.2 (*)
+--- androidx.collection:collection-ktx:1.1.0
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.20 -> 1.4.30 (*)
| \--- androidx.collection:collection:1.1.0 (*)
+--- androidx.lifecycle:lifecycle-livedata-core-ktx:2.3.0
| +--- androidx.lifecycle:lifecycle-livedata-core:2.3.0 (*)
| \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.20 -> 1.4.30 (*)
+--- androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0 (*)
+--- androidx.savedstate:savedstate-ktx:1.1.0 (*)
\--- org.jetbrains.kotlin:kotlin-stdlib:1.4.20 -> 1.4.30 (*)
Search
Get more post