清单列表查看项目[发布APK]

时间:2019-05-14 13:15:15

标签: android listview android-proguard

我有ListView个项目。在Debug模式下,我可以看到ListView的所有项目,但是当我生成发行版APK时,ListView的所有项目都是不可见的,但仍然可以单击,只是项目的文本是不可见的。当我禁用专业后卫时,一切正常。我使用Gson将JSON转换为Java对象。

PROGUARD

# 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);
        }
    }
}

1 个答案:

答案 0 :(得分:2)

  

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

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