Kotlin-android: unresolved reference databinding

后端 未结 16 1100
借酒劲吻你
借酒劲吻你 2020-12-02 16:23

I have following fragment class written in Java using the new databinding library

import com.example.app.databinding.FragmentDataBdinding;

public class Data         


        
16条回答
  •  青春惊慌失措
    2020-12-02 16:47

    Important Update

    You can see in documentation of Android.

    The new compiler in version 3.2 is enabled by default.

    So Just Update your Android Studio to V3.2 or newer. and remove all unnecessary config.

    So just enable dataBinding in app level build.gradle.

    android {
        dataBinding {
            enabled = true
        }
    }
    

    It will do all things for you automatically.

    You can SAFELY REMOVE below lines-

    • Remove databinding.compiler

      kapt 'com.android.databinding:compiler:3.0.1'
      
    • Remove kapt

      kapt {
          generateStubs = true
      }
      

    My complete config

    build.gradle (Project)

    kotlin_version = '1.2.71'    
    classpath 'com.android.tools.build:gradle:3.2.0'
    

    Use gradle latest version. Use kotlin latest version.

    build.gradle (App)

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    
    compileSdkVersion 28
    targetSdkVersion 28
    
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    

    Important Do not just copy and paste config. See this answer for setting up Kotlin version.

    gradle-wrapper.properties

    distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
    

提交回复
热议问题