Room annotation processor with Data binding

前端 未结 3 1501
感动是毒
感动是毒 2020-12-14 12:34

I have used Data binding in my existing code and now I am migrating to Room for persistence. I have followed the steps mentioned in Florina\'s Blog for room

My Code

相关标签:
3条回答
  • 2020-12-14 13:04

    I faced this issue while adding room dependencies. Add this in the below way to resolve the error.

     def roomVersion = "2.0.0-rc01"
    implementation "android.arch.persistence.room:runtime:$roomVersion"
    annotationProcessor "android.arch.persistence.room:runtime:$roomVersion"
    annotationProcessor "android.arch.persistence.room:compiler:$roomVersion"
    
    0 讨论(0)
  • 2020-12-14 13:07

    After 4 days of efforts I finally made my code run properly. Steps to solve the

    Data binding error like error: package com.packagename.databinding does not exist error: cannot find symbol class CustomMainActivityBinding

    The app gradle must have below code added in order to view more than 100 errors that come by default

    allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xmaxerrs" << "4000"
            options.compilerArgs << "-Xmaxwarns" << "4000"
        }
      }
    }
    

    Gradle dependencies for data binding and Room arch components

    annotationProcessor 'com.android.databinding:compiler:3.0.1'
    
    implementation 'android.arch.lifecycle:extensions:1.0.0'
    implementation 'android.arch.persistence.room:runtime:1.0.0'
    annotationProcessor 'android.arch.lifecycle:compiler:1.0.0'
    annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
    

    Note: Gradle plugin version is 3.0.1

    I changed my all VMs to implement Observable and call

    registry.notifyChange(this, BR.bar);
    

    in case of notify change and also implement overridden methods

    @Override
    public void addOnPropertyChangedCallback(OnPropertyChangedCallback    
    callback) {
    registry.add(callback);
    }
    
    @Override
    public void removeOnPropertyChangedCallback(
    OnPropertyChangedCallback callback) {
    registry.remove(callback);
    }
    

    These things made my code Build, but it run without exceptions when I solved the Room query related errors. Which was the main reason, code was building but not running. These errors I could see when I Rebuid my project again.

    UPDATE:

    After Android studio 3.1.3, Message window is gone and now all build error appears under Build view. Although there is toggle available to get textview response of error, for data-binding errors it isn't sufficient.

    Solution that helped me:

    1. In Command promt/Terminal navigate to project root.
    2. Run this command "./gradlew build --stacktrace" if Mac or ".\gradlew build --stacktrace" if Windows.
    3. Now search for "error:" tag and the compile time errors will show up.

    I couldn't get these errors in IDE.

    0 讨论(0)
  • 2020-12-14 13:19

    In my experience, the following reasons may cause the error:

    1. Incorrect getter/setter (missing or incorrect name)
    2. Incorrect return type in Dao
    3. annotationProcessor or kapt issues
    4. The default constructor is overridden (you need to keep the empty constructor for Room)
    0 讨论(0)
提交回复
热议问题