ViewModel in Kotlin: Unresolved Reference

前端 未结 7 1931
离开以前
离开以前 2021-01-07 17:24

I am trying to implement ViewModel in a 100% Kotlin app. Every piece of documentation I can find says I want to use this to get the ViewModel instance:

ViewM         


        
相关标签:
7条回答
  • 2021-01-07 18:25

    In addition to what Sup suggested, you'll have to correct lifecycler:compiler to lifecycle:compiler - the Gradle sync shouldn't even complete successfully with this typo.

    Secondly, the standard android annotation processing ("annotationProcessor") doesn't really work with Kotlin. Instead, use Kotlin's kapt.

    At the top of your build.gradle file, add the following:

    apply plugin: 'kotlin-kapt'.

    And in your dependencies section, replace occurences of annotationProcessor (like the above one) with kapt, e.g.

    kapt "android.arch.lifecycle:compiler:1.1.1"

    0 讨论(0)
提交回复
热议问题