androidandroid-databinding

Data Binding: Cannot find symbol class BR


I try to use Data Binding in my existing project, but I can't get it to build.

Using in Project build.gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:1.3.1'
    //Data Binding Beta
    classpath "com.android.databinding:dataBinder:1.0-rc4"

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7+'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

applying

apply plugin: 'com.android.databinding'
apply plugin: 'com.neenbedankt.android-apt'`

and in Module:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    apt 'com.android.databinding:compiler:1.0-rc1+'
}

I tried to use Data Binding with RecyclerView/Fragment/ViewHolder/Adapter.. I use Android Studio 1.4.1. With compileSdkVersion 23 and buildToolsVersion "23.0.1". I tried it without apt, different gradle versions, proof read my classes/xml.. I also use still Butterknife(since my project is too big to change everything at once) and other (but unrelevant) libraries. I synced and rebuild my project, I closed/opened Android Studio, I tried to invalidate caches. I build a 'fresh' example from start, which worked fine.

My getter Methods in my "data class" are @Bindable.

Also, the databinding package is not created. (error message says it doesn't exist) and Error:cannot generate view binders java.lang.StringIndexOutOfBoundsException: String index out of range: -21


Solution

  • I got the Error:cannot generate view binders java.lang.StringIndexOutOfBoundsException: String index out of range: -21 error almost everytime when I tried to use a ObservableList with custom objects. But I found out, that almost everytime I forgot a > after my type. Silly me. So, my solution was to check for it:

        <data>
    
            <import type="android.databinding.ObservableArrayList"/>
    
            <variable
                name="dices"
                type="ObservableArrayList&lt;Dice>" /> //don't forget the '>' after Dice
        </data>