Android Studio fails to generate databinding after 3.1.0 update

前端 未结 20 2884
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  • Ok, so those who are wondering how I fixed this. The solution is quite simple but probably you won't like it.

    I had to move all my classes that were used in data binding in the project root package and after it started to work again.

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

    Just Commenting these lines out in graddle-wrapper.properties file helped me solve my problem

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

    This one is a very tricky bug with android studio and databinding! I had to test all this proposed solutions and some more for an entire day to finally make the databinding compile at least.

    So I had to disable all databindind settings in gradle.properties file, just comment these lines or delete them:

    android.databinding.enableV2 = true
    android.enableExperimentalFeatureDatabinding = true
    

    remove buildToolsVersion from build.gradle and have the following sdk versions:

    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    

    Plus a couple more clean/rebuild invalidate caches and restart, and it FINALLY compiled. AS engineers are great at creating bugs!

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

    This might not be the most helpful answer, but in my case this was caused by a completely unrelated issue in my code.

    I was receiving 51 error: cannot find symbol: DataBindingComponent errors (in every single Data Binding generated class), and I spent ages removing changes to my XML and ViewModel code trying to find what was causing it.

    The problem actually lay in an invalid change I made a Room model. I guess that a Room error might have been obfuscated by all the databinding errors, but the Debug/Scan logs in the terminal didn't point to it.

    So review all recent code, even seemingly unrelated changes if you encounter this problem.

    Edit: See this SO post about these databinding errors obfuscating other kapt issues (like Room / Dagger)

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

    I got this error after making some modifications in Room Entity classes. So I feel that This error is somehow related to Room library. Try to revert changes in Room classes and entities or comment them to see if error is fixed.

    In my case the error appeared because I was returning int from insert and update methods. These methods should not return anything. So removing return fixed the error.

    @Insert(onConflict = OnConflictStrategy.REPLACE)
        fun insert(student: Student):Int
    

    to

    @Insert(onConflict = OnConflictStrategy.REPLACE)
        fun insert(student: Student)
    
    0 讨论(0)
  • 2020-12-15 03:24

    I was having the same issue. Fixed it by adding google() to Project build.gradle

    allprojects {
        repositories {
            jcenter()
            **google()**
        }
    }
    

    make sure you add in allProjects

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