Android Proguard-IllegalStateException:创建ViewHolder视图时不得附加视图

Android Proguard-IllegalStateException:创建ViewHolder视图时不得附加视图,android,android-recyclerview,proguard,Android,Android Recyclerview,Proguard,启用minifyEnabled后,在我的gradle文件中启用ḿy应用程序继续崩溃。我已经搜索了很多,但我觉得与Proguard不太适应,我也不确定问题出在哪里。也许我需要添加更多的keep in proguard rules pro 格雷德尔先生 buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFi

启用minifyEnabled后,在我的gradle文件中启用ḿy应用程序继续崩溃。我已经搜索了很多,但我觉得与Proguard不太适应,我也不确定问题出在哪里。也许我需要添加更多的keep in proguard rules pro

格雷德尔先生

buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
proguard-rules.pro

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

##---------------End: proguard configuration for Gson  ----------

-keep class com.sterbsociety.** {*;}
-keep class package.model.* {*;}
-keep class androidx.recyclerview.widget.RecyclerView.** {*;}
-keepattributes *Annotation*,Signature, InnerClasses
错误:

java.lang.IllegalStateException: ViewHolder views must not be attached when created. Ensure that you are not passing 'true' to the attachToRoot parameter of LayoutInflater.inflate(..., boolean attachToRoot)
        at androidx.recyclerview.widget.RecyclerView$a.createViewHolder(:6)
        at androidx.recyclerview.widget.RecyclerView$p.a(:60)
        at androidx.recyclerview.widget.RecyclerView$p.a(:26)
        at androidx.recyclerview.widget.RecyclerView$p.c(:2)

有什么想法吗?提前感谢。

错误可能与proguard无关,但与如何为ViewHolder扩展布局有关。尝试确保使用
false
参数对布局进行充气,如下所示:

  @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    Context context = viewGroup.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);

    // Inflate the custom layout, use false.
    View contactView = inflater.inflate(R.layout.item_of_yours, viewGroup, false);

    ...

    return viewHolder;
  }

不,这不是问题所在。我最终通过在proguard文件规则中保留一些类来解决这个问题。