androidkotlinandroidxcamera-view

Unresolved reference: setLifecycleOwner in AndroidX


MainActivity.kt: (41, 16): Unresolved reference: setLifecycleOwner

Task :app:buildInfoGeneratorDebug

My app uses AndroidX, in my gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

My Code in onCreate function in MainActivity.tk:

val camera = findViewById<View>(R.id.camera)
    camera.setLifecycleOwner(this)

Trying to implment the CameraView.


Solution

  • You cast your library view type to android basic View which hasn't such method.
    You should change your findViewById<View> to findViewById<CameraView>