Kotlin-android: unresolved reference databinding

后端 未结 16 926
借酒劲吻你
借酒劲吻你 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:54

    I found new solution, hope it will helps you.

    First of all check whether plugin applied:

    apply plugin: 'kotlin-kapt'
    

    then

    android {
        ...
        ...
        dataBinding {
            enabled = true
        }
        ...
        ...
    }
    

    You might have an error in dependency:

    USE

    kapt 'com.android.databinding:compiler:3.1.4'
    

    instead of

    compile 'com.android.databinding:compiler:3.1.4'
    

    You can visit here for new version

    Thank you.

    0 讨论(0)
  • 2020-12-02 16:54

    Before you try to use FragmentDetailsBinding you have to make sure you converted the corresponding layout( fragment_details.xml ) to data binding layout by wrapping the whole layout in "" tag parent and move all of xmlns to layout tag then build the project and thats it

    0 讨论(0)
  • 2020-12-02 16:55

    Try use this configuration:

    In main build.gradle:

    buildscript {
        ext.kotlin_version = '<kotlin-version>'
        ext.android_plugin_version = '2.2.0-alpha4'
        dependencies {
            classpath "com.android.tools.build:gradle:$android_plugin_version"
        //... rest of the content
        }
    }
    

    App build.gradle:

    android {
        dataBinding {
            enabled = true
        }
    }
    
    dependencies {
        kapt "com.android.databinding:compiler:$android_plugin_version"
    }
    
    kapt {
        generateStubs = true
    }
    
    0 讨论(0)
  • 2020-12-02 16:56

    Try this.Andrid studio 2.0(2.1)

    In build.gradle

    android{
       dataBinding {
            enabled = true
        }
    ...
    }
    dependencies {
     kapt 'com.android.databinding:compiler:2.0.0-rc1'
    ....
    }
    
    kapt {
        generateStubs = true
    }
    

    In my project: buildToolsVersion = "23.0.3"

    in top level build.gradle

    dependencies {
            classpath 'com.android.tools.build:gradle:2.0.0'
        }
    
    0 讨论(0)
  • 2020-12-02 16:56

    In my case I only forgot to add in layout file the header:

    <layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
    
    ....
    
    0 讨论(0)
  • 2020-12-02 16:58

    Add Databinding in android Project using when you have use kotlin language.

    Below steps

    --First you need to add the below plugin

    **apply plugin: 'kotlin-kapt'**
    

    --Second dataBinding enabled true

    **dataBinding {
            enabled = true
        }**
    

    All this point added in app.build.gradle after hit "SYNC NOW"

    Lets For example you have edit profile activity then how to define binding variable in kotlin??

    lateinit var buildProfileBinding: ActivityBuildProfileBinding
    
    buildProfileBinding = getBinding()
    

    Here,get binding is method to handle which type of binding object

    protected <T extends ViewDataBinding> T getBinding() {
                    return (T) binding;
                }
    
    0 讨论(0)
提交回复
热议问题