JakeWharton / RxBinding

RxJava binding APIs for Android's UI widgets.
Apache License 2.0
9.68k stars 971 forks source link

Tools attribute listitem not working #498

Closed dexpota closed 5 years ago

dexpota commented 5 years ago

The preview of a RecyclerView with the tools:listitem attribute doesn't work when RxBinding 3.0.0-alpha2 is a dependency.

The preview window launch the following error:

java.lang.ClassNotFoundException: androidx.recyclerview.widget.RecyclerView$Adapter
    at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:190)
    at com.android.tools.idea.rendering.RenderClassLoader.findClass(RenderClassLoader.java:61)
    at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:124)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:224)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:642)
    at com.android.tools.idea.rendering.RenderClassLoader.defineClassAndPackage(RenderClassLoader.java:197)
    at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:141)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:224)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:422)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:176)
    at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:137)
    at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadClass(LayoutlibCallbackImpl.java:306)
    at com.android.layoutlib.bridge.android.support.RecyclerViewUtil.createAdapter(RecyclerViewUtil.java:122)
    at com.android.layoutlib.bridge.android.support.RecyclerViewUtil.setAdapter(RecyclerViewUtil.java:64)
    at android.view.BridgeInflater.setupViewInContext(BridgeInflater.java:467)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:350)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
    at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:863)
    at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:837)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:325)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:385)
    at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:193)
    at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:509)
    at com.android.tools.idea.rendering.RenderTask.lambda$inflate$4(RenderTask.java:638)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

The issue can be easily recreated with a basic android project and the following layouts.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="ciao"/>

</LinearLayout>

item.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
            tools:listitem="@layout/item"
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>

activity_main.xml

I am not sure the issue is totally on RxBinding

JakeWharton commented 5 years ago

3.0.0 only works with AndroidX and you have a legacy support library type in the layout. Either migrate it to AndroidX or use RxBinding 2.x.