1

Compile time error occurs when I try to run with ProGuard and data binding enabled.

Note : Same code works when proGuard is disabled.

Here is the console error message

Cannot find the setter for attribute 'bind:itemOrders' with parameter type java.util.List<com.example.boss.ItemOrder> on android.support.v7.widget.RecyclerView.

Here is my layout where I bind recycler view using bind attribute.

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:bind="http://schemas.android.com/apk/res-auto">
    <data>
        <import type="android.view.View" />
        <variable
            name="viewModel"
            type="com.example.boss.BossViewModel" />
    </data>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
                android:id="@+id/itemOrderRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                style="@style/ItemOrders"
                bind:itemOrders="@{viewModel.itemOrders}"/>
    </RelativeLayout>
</layout>

Here is my custom data binding method

@BindingAdapter("bind:itemOrders")
public static void bindList(RecyclerView view, List<ItemOrder> itemOrders) {
    view.setLayoutManager(new LinearLayoutManager(view.getContext()));
    view.setAdapter(new ItemOrderAdapter(itemOrders));
}

Here is my proguard-rules.pro file

-keepclassmembers public class com.example.boss.BossViewModel{*;}
-keep class android.databinding.** { *; }    
-keepattributes *Annotation*    
-keepattributes javax.xml.bind.annotation.*    
-keepattributes javax.annotation.processing.*  

-keepclassmembers class ** {
    @android.databinding.BindingAdapter public *;
}

-dontwarn android.databinding.**
Fahadsk
  • 1,099
  • 10
  • 24
  • You should be using `@BindingAdapter("itemOrders")` instead of `@BindingAdapter("bind:itemOrders")` – blizzard Feb 15 '17 at 17:20
  • @blizzard thnx, i have tried it but not luck also plz note that the same code works when proGuard is disabled. – Fahadsk Feb 15 '17 at 17:29

1 Answers1

1

You need to change namespace shcema from

xmlns:bind="http://schemas.android.com/apk/res-auto"

to

xmlns:bind="http://schemas.android.com/apk/tools"

Also, you can remove bind prefix from @BindingAdapter definition - this name space will be ignored.

Sergei Bubenshchikov
  • 5,275
  • 3
  • 33
  • 60