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

后端 未结 18 1743
小蘑菇
小蘑菇 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:23

    Faced the same issue.

    Reason for "cannot resolve ActivityMainBinding" is that your Binding file isn't generated. Try to clean and rebuild project. Also make sure you have followed the steps :

    1. classpath "com.android.databinding:dataBinder:1.0-rc4" --> include this in main module build file
    2. apply plugin: 'com.android.databinding' to your app module you are building
    3. Clean
    4. Rebuild. Check under ,if build->indermediates->your package name->databinding folder is generated containing ActivityMainBinding class.

    Alternatively if you want to see the generated source.

    1. classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7' -->apply to your main module.
    2. apply plugin: 'com.neenbedankt.android-apt' --> to you app module
    3. apt 'com.android.databinding:compiler:1.0-rc0' --> include in your dependencies.

    These classes will be generated on first build. Also make sure the applicationId in your application module is same as the package name in AndroidManifest.xml of your app module. Hope this helps.

提交回复
热议问题