Android - DataBinding - How and when the Binding classes will be generated?

后端 未结 18 1734
小蘑菇
小蘑菇 2021-02-03 16:51

DataBinding Guide States

  By default, a Binding class will be generated based on the name of the layout 
file, converting it to Pascal case and suffixing “Bindi         


        
18条回答
  •  盖世英雄少女心
    2021-02-03 17:21

    For android databinding to work properly you have to use android tools for gradle (com.android.tools.build:gradle) >=1.3.0.

    So your project build.gradle must look like:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.3.0'
            classpath "com.android.databinding:dataBinder:1.0-rc1"
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    

    And module build.gradle must have that plugin:

    apply plugin: 'com.android.databinding'
    

    After all, check in your module you're using latest buildToolsVersion (right now it is 22.0.1). I am not sure that's required but it possibly will make you feel good about you're on the "bleeding edge of technology" ^_^ :

    buildToolsVersion '22.0.1'
    

    Resync gradle and rebuild your project. It is likely possible that without rebuild of project you might not get SomeLayoutBinding classes generated.

    In Android Studio that could be done from application menu: Build -> Rebuild project

提交回复
热议问题