Epoxy: Unable to use with DataBindings and AndroidX when not using 3.0.0-rc1

Created on 26 Oct 2018  路  18Comments  路  Source: airbnb/epoxy

Hi I tried it with a simple DataBinding as a Model but building gives me:

e: error: Epoxy Processor Exception: Caused by TypeCastException: null cannot be cast to non-null type javax.lang.model.element.TypeElement Stacktrace: com.airbnb.epoxy.DataBindingModelInfo.<init>(DataBindingModelInfo.kt:27) com.airbnb.epoxy.DataBindingModelInfo.<init>(DataBindingModelInfo.kt:16) com.airbnb.epoxy.DataBindingProcessor.process(DataBindingProcessor.kt:33) com.airbnb.epoxy.EpoxyProcessor.processRound(EpoxyProcessor.java:189) com.airbnb.epoxy.EpoxyProcessor.process(EpoxyProcessor.java:165)

I do use Kotlin and AndroidX.

My Model XML looks like this:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
    <data>
        <variable
            name="displayName"
            type="String" />
        <variable
            name="lastMessage"
            type="String" />
    </data>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackground">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/roomImage"
            android:layout_width="@dimen/dialog_avatar_width"
            android:layout_height="@dimen/dialog_avatar_height"
            android:layout_margin="16dp"/>

        <TextView
            android:id="@+id/displayNameID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="19dp"
            android:layout_toEndOf="@id/roomImage"
            android:layout_toLeftOf="@id/dialogDate"
            android:layout_toRightOf="@id/roomImage"
            android:layout_toStartOf="@id/dialogDate"
            android:ellipsize="end"
            android:fontFamily="@string/font_fontFamily_medium"
            android:includeFontPadding="false"
            android:maxLines="1"
            android:text="@{displayName}"/>

        <TextView
            android:id="@id/dialogDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            android:ellipsize="end"
            android:maxLines="1"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/displayNameID"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="7dp"
            android:layout_toEndOf="@id/roomImage"
            android:layout_toLeftOf="@+id/dialogUnreadBubble"
            android:layout_toRightOf="@id/roomImage"
            android:layout_toStartOf="@+id/dialogUnreadBubble">

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@id/dialogLastMessageUserAvatar"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_marginEnd="7dp"
                android:layout_marginRight="7dp"/>


            <TextView
                android:id="@+id/lastMessageID"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toEndOf="@id/dialogLastMessageUserAvatar"
                android:layout_toRightOf="@id/dialogLastMessageUserAvatar"
                android:ellipsize="end"
                android:gravity="top"
                android:maxLines="1"
                android:text="@{lastMessage}"/>

        </RelativeLayout>

        <TextView
            android:id="@id/dialogUnreadBubble"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_below="@id/dialogDate"
            android:layout_marginEnd="24dp"
            android:layout_marginRight="24dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/bubble_circle"
            android:ellipsize="end"
            android:fontFamily="@string/font_fontFamily_medium"
            android:gravity="center"
            android:lines="1"/>

        <FrameLayout
            android:id="@id/dialogDividerContainer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginTop="16dp">

            <View
                android:id="@id/dialogDivider"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/dialog_divider"/>

        </FrameLayout>

    </RelativeLayout>
</layout>

My package-info.java looks like this:

@EpoxyDataBindingLayouts({R.layout.room_element})
package blog.nordgedanken.simplematrix.roomView.recyclerView;

import com.airbnb.epoxy.EpoxyDataBindingLayouts;
import blog.nordgedanken.simplematrix.R;

I do use 3.0.0-rc1 with kapt as I use Kotlin

Most helpful comment

@markusressel in the end it was a combination of having clashing id namings and variables together with inconsistent epoxy versions. One of them was using an older version :/

All 18 comments

PS my App consists of a mobile and a wear module

After fixing that variable name and id are the same I got this now:

e: error: Epoxy Processor Exception: Error generating model classes Caused by NullPointerException: null Stacktrace: com.airbnb.epoxy.Utils.areParamsTheSame(Utils.java:300) com.airbnb.epoxy.Utils.getMethodOnClass(Utils.java:270) com.airbnb.epoxy.Utils.implementsMethod(Utils.java:244) com.airbnb.epoxy.GeneratedModelWriter.generateDataBindingMethodsIfNeeded(GeneratedModelWriter.kt:1131) com.airbnb.epoxy.GeneratedModelWriter.generateClassForModel(GeneratedModelWriter.kt:164) com.airbnb.epoxy.GeneratedModelWriter.generateClassForModel$default(GeneratedModelWriter.kt:134) com.airbnb.epoxy.DataBindingProcessor.resolveDataBindingClassesAndWriteJava(DataBindingProcessor.kt:104) com.airbnb.epoxy.DataBindingProcessor.process(DataBindingProcessor.kt:81) com.airbnb.epoxy.EpoxyProcessor.processRound(EpoxyProcessor.java:189) com.airbnb.epoxy.EpoxyProcessor.process(EpoxyProcessor.java:165)

Hm seems to build now after a full rebuild

Did you follow the instructions here:
https://github.com/airbnb/epoxy/wiki/Data-Binding-Support

and added

implementation "com.airbnb.android:epoxy-databinding:$epoxyVersion"

to your build.gradle?

EDIT: Ah sorry, had an old version of this thread opened in browser and didn't know you already closed it.

@markusressel in the end it was a combination of having clashing id namings and variables together with inconsistent epoxy versions. One of them was using an older version :/

I'm having the same problem. I'm trying to use 2.19.0 with Kotlin + AndroidX + DataBinding and get this error:

e: error: Epoxy Processor Exception: Error generating model classes Caused by NullPointerException: null       
Stacktrace:      com.airbnb.epoxy.Utils.areParamsTheSame(Utils.java:296)       com.airbnb.epoxy.Utils.getMethodOnClass(Utils.java:266)       com.airbnb.epoxy.Utils.implementsMethod(Utils.java:240)       com.airbnb.epoxy.GeneratedModelWriter.generateDataBindingMethodsIfNeeded(GeneratedModelWriter.kt:970)       com.airbnb.epoxy.GeneratedModelWriter.generateClassForModel(GeneratedModelWriter.kt:145)       com.airbnb.epoxy.GeneratedModelWriter.generateClassForModel$default(GeneratedModelWriter.kt:116)       com.airbnb.epoxy.DataBindingProcessor.resolveDataBindingClassesAndWriteJava(DataBindingProcessor.kt:104)       com.airbnb.epoxy.DataBindingProcessor.process(DataBindingProcessor.kt:81)       com.airbnb.epoxy.EpoxyProcessor.processRound(EpoxyProcessor.java:189)       com.airbnb.epoxy.EpoxyProcessor.process(EpoxyProcessor.java:165)

I added everything correctly to app.build:

implementation 'com.airbnb.android:epoxy:2.19.0'
implementation "com.airbnb.android:epoxy-databinding:2.19.0"
implementation 'com.airbnb.android:epoxy-paging:2.19.0'
kapt 'com.airbnb.android:epoxy-processor:2.19.0'

I know of 3.0 but I need the new PagedListEpoxyController.

I don't thing versions lower than 3.0 are compatible with androidx, are they?

Except for some parts, they are. I can use PagedListEpoxyController if I use ViewHolders, but not with DataBinding.

@tsuharesu I currently use PagedListEpoxyController + AndroidX + epoxy + DataBindings. Important for me was that I need all versions to be the latest 3.X version of epoxy. Also make sure that your item IDs dont clash with the databinding variable IDs. Because they seem to break the generating part

@MTRNord PagedListEpoxyController is part of 2.18+, not 3.0.
3.0 still uses PagingEpoxyController (and I'm having a problem with it).

https://github.com/airbnb/epoxy/blob/master/CHANGELOG.md#2180-sep-26-2018

@tsuharesu oh I just realised that. PagedList vs Paging :/ I indeed use Paging

@tsuharesu actually it seems like androidX still is only a PR and not has landed in general and looking at the tag order 3.0.0-rc1 is much older than 2.19 :/

But indeed 2.19 fails. I guess someone else can resolve the confusing if 3.0.0-rc1 is actually newer or not and what might cause the issue if 2.19 is indeed newer as github tagging shows

2.19+ is stuck generating with this error:

e: error: Epoxy Processor Exception: Error generating model classes Caused by NullPointerException: null Stacktrace: com.airbnb.epoxy.Utils.areParamsTheSame(Utils.java:300) com.airbnb.epoxy.Utils.getMethodOnClass(Utils.java:270) com.airbnb.epoxy.Utils.implementsMethod(Utils.java:244) com.airbnb.epoxy.GeneratedModelWriter.generateDataBindingMethodsIfNeeded(GeneratedModelWriter.kt:1131) com.airbnb.epoxy.GeneratedModelWriter.generateClassForModel(GeneratedModelWriter.kt:164) com.airbnb.epoxy.GeneratedModelWriter.generateClassForModel$default(GeneratedModelWriter.kt:134) com.airbnb.epoxy.DataBindingProcessor.resolveDataBindingClassesAndWriteJava(DataBindingProcessor.kt:104) com.airbnb.epoxy.DataBindingProcessor.process(DataBindingProcessor.kt:81) com.airbnb.epoxy.EpoxyProcessor.processRound(EpoxyProcessor.java:189) com.airbnb.epoxy.EpoxyProcessor.process(EpoxyProcessor.java:165)

3.0 is older https://github.com/airbnb/epoxy/releases.
We need to wait for all 2.1x changes to be merged to 3.0.

Right now my workaround is to not use Databinding.

I guess I will wait in that case. As I just rebuilt my App with databindings. Means I dont want to rework it again :)

@tsuharesu It seems like you can use the androidX PR changes using the latest build on https://jitpack.io/#jeffreydelooff/epoxy It includes the new features

3.0.0 is finally out with androidx and all latest epoxy updates

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carlosmuvi picture carlosmuvi  路  3Comments

chrisbanes picture chrisbanes  路  3Comments

saurabhdtu picture saurabhdtu  路  6Comments

Sergiyss picture Sergiyss  路  6Comments

AdamMc331 picture AdamMc331  路  6Comments