gpt4 book ai didi

安卓 : ProGuard cannot find setter for attribute "bind:items" in recycler view inside layout

转载 作者:行者123 更新时间:2023-11-30 00:43:04 26 4
gpt4 key购买 nike

当我尝试在启用 ProGuard 和数据绑定(bind)的情况下运行时发生编译时错误。

注意:当 proGuard 被禁用时,相同的代码仍然有效。

这是控制台错误信息

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

这是我的布局,我使用绑定(bind)属性绑定(bind)回收器 View 。

<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>

这是我的自定义数据绑定(bind)方法

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

这是我的 proguard-rules.pro 文件

-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.**

最佳答案

您需要更改 namespace shcema

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

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

此外,您可以从 @BindingAdapter 定义中删除 bind 前缀 - 这个 namespace 将被忽略。

关于安卓 : ProGuard cannot find setter for attribute "bind:items" in recycler view inside layout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42255578/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com