Android Studio fails to generate databinding after 3.1.0 update

前端 未结 20 2887
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 02:40

This morning I made an update to android studio from 3.0.1 to 3.1.0. After updating the gradle to latest version I still get build error regarding

相关标签:
20条回答
  • 2020-12-15 03:31

    Adding these lines in grade.properties helped me save the issue

    android.enableExperimentalFeatureDatabinding = true
    android.databinding.enableV2=true
    
    0 讨论(0)
  • 2020-12-15 03:32

    This may seems strange but I wasted a few hours facing the error and after a inspection in my latest changes I found that it was related to an error in Room database.

    I declared one of the Dao interface but forgot to anotate it with @Dao.

    After fixing that the data binding error was fixed.

    I guess this is a bug of android studio.

    0 讨论(0)
  • 2020-12-15 03:34

    Check your xml files if you are using databinding. I wasted one hour today because I renamed one class and Android Studio decided to make changes in my xml files. For example, I had a class named LiveGameModel and I renamed to LiveGameView and AS decided to make changes in xml files which are not related to this view. I know, this bug doesn't make sense.

    0 讨论(0)
  • 2020-12-15 03:35

    FIRST OF ALL
    1. add "layout" to your root layout

    1. Build -> Make Project (for create generate class after add "layout")
    2. //binding private lateinit var binding:ActivityLoginBinding
    3. in oncreate view //setContentView(R.layout.activity_login) binding = DataBindingUtil.setContentView(this@LoginActivity,R.layout.activity_login)
    0 讨论(0)
  • 2020-12-15 03:37

    To fix this error in Java project you shouild rollback to supportLibraryVersion - 27.0.2 from 27.1.0 Works fine with AndroidStudio 3.1 and com.android.tools.build:gradle:3.1.0

    Waiting for a fix from the Google

    0 讨论(0)
  • 2020-12-15 03:37

    I got this while updating gradle to 3.4.2. All you need to do is remove the import statement of java.lang.

    Caution: Android Studio doesn't yet handle imports so the autocomplete for imported variables may not work in your IDE. Your app still compiles and you can work around the IDE issue by using fully qualified names in your variable definitions.

    Source: https://developer.android.com/topic/libraries/data-binding/expressions#import-classes

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