Unresolved reference: BR (Android Studio)

后端 未结 4 2053
孤独总比滥情好
孤独总比滥情好 2021-01-01 13:47

My top level build.gradle:

buildscript {
    ext.kotlin_version = \'1.2.41\'
    ext.lifecycle_version = \"1.1.1\"
    repositories {
        google()
               


        
相关标签:
4条回答
  • 2021-01-01 14:28

    For Android Studio 3.3, Gradle 3.3.0 and Databinding v2, the only line that needs to be added to fix this issue is in your (app's or modules) build.gradle:

    apply plugin: "kotlin-kapt"
    
    0 讨论(0)
  • 2021-01-01 14:32

    Android Studio failed to import my BR class automatically. All solutions provided above failed. I just had to import the class manually, Android studio had created it correctly.

    SAMPLE:

    package your_packagename
    
    import your_packagename.BR
    import ...
    ...
    
    

    I think this happened due to Copy and Paste. When i typed BR manually, Android Stdio did the Automatic Import.

    0 讨论(0)
  • 2021-01-01 14:45

    I manually typed the line "binding.setVariable(BR.item, item)" and it worked for me. Android studio shows the suggestion of importing BR. Choose the one from your project. Also enable databinding = true in gradle.

    0 讨论(0)
  • 2021-01-01 14:46

    After researching quite a bit, turns out there are a couple things to add in order to use data binding library

    project build.gradle

    buildscript {
        ext {
            compiler_version = '3.1.3'
        }
        dependencies {
            classpath "com.android.tools.build:gradle:$compiler_version"
        }
    }
    

    app build.gradle

    apply plugin: 'kotlin-kapt'
    
    android {
        dataBinding {
            enabled = true
        }
    }
    
    dependencies {
        kapt "com.android.databinding:compiler:$compiler_version"
    }
    
    kapt {
        generateStubs = true
    }
    

    I started to have some warnings after adding the data binding library, like 3rd-party Gradle plug-ins may be the cause and Classpath entry points to a non-existent location. But compiles and runs fine

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