我有很多东西。在ListView模式下,我可以看到Debug的所有项,但是当我生成release apk时,listview的所有项都是不可见的,但仍然可以单击,只有项的文本是不可见的。当我禁用pro-guard时,一切正常。我使用gson将json转换为java对象。
前锋:

# 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.** { <fields>; }

# 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

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

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

更新:
帮手:
public class PlazaHelper {
    public static List<PlazaModel> retrievePlazaHelper(Context context) {
        Reader reader = new InputStreamReader(context.getResources().openRawResource(R.raw.nightwaveplazalinks));
        return (new Gson()).fromJson(reader, new TypeToken<List<PlazaModel>>() {
        }.getType());
    }
}

模型
public class PlazaModel {

    private String name;

    @SerializedName("stream")
    private String url;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
}

适配器
public class PlazaListAdapter extends BaseAdapter {

    private Activity activity;
    private List<PlazaModel> PlazaModels;

    public PlazaListAdapter(Activity activity, List<PlazaModel> PlazaModels) {
        this.activity = activity;
        this.PlazaModels = PlazaModels;
    }

    @Override
    public int getCount() {
        return PlazaModels.size();
    }

    @Override
    public Object getItem(int position) {
        return PlazaModels.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        LayoutInflater inflater = activity.getLayoutInflater();
        ViewHolder holder;
        if (view != null) {
            holder = (ViewHolder) view.getTag();
        } else {
            view = inflater.inflate(R.layout.list_item_style, parent, false);
            holder = new ViewHolder(view);
            view.setTag(holder);

        }
        PlazaModel plazaModel = (PlazaModel) getItem(position);
        if (plazaModel == null) {
            return view;
        }
        holder.text.setTextColor(Color.BLACK);
        holder.text.setText(plazaModel.getName());
        return view;
    }

    static class ViewHolder {
        TextView text;

        ViewHolder(View view) {
            text = view.findViewById(R.id.txt_result);
        }
    }
}

最佳答案

您应该keep指定包中所有公共类的名称
子包装。

-keep class packageName.subPackageName.** { *; }

10-08 01:42