У меня есть приложение, которое извлекает данные с сервера и использует GSON, чтобы заполнить их в представлении переработчика. Отладочная версия с minifyEnabled false прекрасно работает, но когда она установлена в значение true, она возвращает нулевые данные из класса Model, я добавила правила proguard для gson и даже для этого класса, но не работающие
правила proguard
# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
#### -- Picasso --
-dontwarn com.squareup.picasso.**
#### -- OkHttp --
-dontwarn com.squareup.okhttp.internal.**
#### -- Apache Commons --
-dontwarn org.apache.commons.logging.**
-ignorewarnings
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-printusage
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizations !method/inlining/*
-optimizationpasses 5
-allowaccessmodification
#-assumenosideeffects class android.util.Log{
#public static *** d(...);
#public static *** i(...);
#public static *** v(...);
#}
# 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
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class com.shockwave.**
-keepclassmembers class **.R$* {
public static <fields>;
}
-keep class net.sqlcipher.** {
*;
}
#-keep class com.google.gson.stream.** { *; }
-keep class com.udaan.recstudentportalV2.NoticeAct { *; }
-keep class com.udaan.recstudentportalV2.Notice { *; }
-keep class com.udaan.recstudentportalV2.NoticeAdapter { *; }
-keep class com.udaan.recstudentportalV2.NoticePojo { *; }
-keep class com.uddan.recstudnetportalV2.Gallery {*;}
-keep class com.uddan.recstudnetportalV2.Album
-keep class com.uddan.recstudnetportalV2.AlbumImageAdapter {*;}
-keep class com.uddan.recstudnetportalV2.AlbumImage
-keep class com.uddan.recstudnetportalV2.AlbumAdapter {*;}
-keep class com.uddan.recstudnetportalV2.AlbumViewActivity {*;}
-keep class com.udaan.recstudentportalV2.Question { *; }
-keep class com.udaan.recstudentportalV2.QuestionAct { *; }
-keep class com.udaan.recstudentportalV2.QuestionDisplay { *; }
-keep class com.udaan.recstudentportalV2.QuestionPojo { *; }
-keep class com.udaan.recstudentportalV2.Questions { *; }
-keep class com.udaan.recstudentportalV2.Result { *; }
-keep class com.udaan.recstudentportalV2.ResultAct { *; }
-keep class com.udaan.recstudentportalV2.ResultAdapter { *; }
-keep class com.udaan.recstudentportalV2.ResultDisplay { *; }
-keep class com.udaan.recstudentportalV2.ResultPojo { *; }
-keep class com.udaan.recstudentportalV2.Assignment { *; }
-keep class com.udaan.recstudentportalV2.AssignmentAct { *; }
-keep class com.udaan.recstudentportalV2.AssignmentAdapter { *; }
-keep class com.udaan.recstudentportalV2.AssignmentDisplay { *; }
-keep class com.udaan.recstudentportalV2.AssignmentPojo { *; }
-keep class com.udaan.recstudentportalV2.Syllabus { *; }
-keep class com.udaan.recstudentportalV2.SyllabusAct { *; }
-keep class com.udaan.recstudentportalV2.SyllabusAdapter { *; }
-keep class com.udaan.recstudentportalV2.SyllabusDisplay { *; }
-keep class com.udaan.recstudentportalV2.SyllabusPojo { *; }
-keep class com.udaan.recstudentportalV2.Notes { *; }
-keep class com.udaan.recstudentportalV2.NotesAct{ *; }
-keep class com.udaan.recstudentportalV2.NotesAdapter { *; }
-keep class com.udaan.recstudentportalV2.NotesDisplay { *; }
-keep class com.udaan.recstudentportalV2.NotesPojo { *; }
-keep class com.udaan.recstudentportalV2.Success { *; }
-keep class com.udaan.recstudentportalV2.SuccessAct { *; }
-keep class com.udaan.recstudentportalV2.SuccessAdapter { *; }
-keep class com.udaan.recstudentportalV2.SuccessPojo { *; }
-keep class com.udaan.recstudentportalV2.Likes { *; }
-keep class com.udaan.recstudentportalV2.Comments { *; }
-keep class com.udaan.recstudentportalV2.CommentAdapter { *; }
-keep class com.udaan.recstudentportalV2.CommentModel { *; }
-keep class com.udaan.recstudentportalV2.NewsfeedFragment { *; }
-keep class com.udaan.recstudentportalV2.Newsfeed { *; }
-keep class com.udaan.recstudentportalV2.Newsfeed_data { *; }
-keep class com.udaan.recstudentportalV2.NewsfeedAdapter { *; }
-keep class com.udaan.recstudentportalV2.NewsfeedPojo { *; }
-keep class com.udaan.recstudentportalV2.TeamUdaan { *; }
-keep class com.udaan.recstudentportalV2.Members { *; }
-keep class com.udaan.recstudentportalV2.MembersPojo { *; }
-keep class com.udaan.recstudentportalV2.UdaanAdapter { *; }
-keep class com.udaan.recstudentportalV2.UdaanFounterAdapter { *; }
-keep class com.udaan.recstudentportalV2.Complain { *; }
# 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
Album. java
package com.udaan.recstudentportalV2;
import com.google.gson.annotations.SerializedName;
public class Album {
@SerializedName("id")
private String id;
@SerializedName("category")
private String category;
@SerializedName("headphoto")
private String headphoto;
@SerializedName("catName")
private String catName;
public Album(String id, String category, String headphoto, String catName) {
this.id = id;
this.category = category;
this.headphoto = headphoto;
this.catName = catName;
}
public Album(){
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getHeadphoto() {
return headphoto;
}
public void setHeadphoto(String headphoto) {
this.headphoto = headphoto;
}
public String getCatName() {
return catName;
}
public void setCatName(String catName) {
this.catName = catName;
}
}
AlbumAdapter. java
package com.udaan.recstudentportalV2;
import android.content.Context;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import com.udaan.recstudentportalV2.util.UrlManager;
public class AlbumAdapter extends RecyclerView.Adapter<AlbumAdapter.ViewHolder> {
UrlManager urlManager = new UrlManager();
private Context context;
private Album[] data;
public AlbumAdapter(Context context, Album[] data){
this.context=context;
this.data=data;
//Log.i("HEADPHOTO",data[1].toString());
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
View view= inflater.inflate(R.layout.rv_row,viewGroup,false);
Log.i("Holder","Created");
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int i) {
String url=urlManager.getBaseUrl();
//Log.i("Album",data[i].getHeadphoto());
final Album album = data[i];
//Log.i("Album",album.getHeadphoto());
viewHolder.albumTextView.setText(album.getCategory());
Glide.with(viewHolder.albumImageView.getContext()).load(url+album.getHeadphoto()).into(viewHolder.albumImageView);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,album.getCategory()+" Was Clicked",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(v.getContext(), AlbumViewActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("albumId",album.getCategory());
// Log.i("CAT",""+album.getCategory());
// Log.i("CAT",""+album.getId());
// Log.i("CAT",""+album.getHeadphoto());
// Log.i("CAT",""+album.getCatName());
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return data.length;
}
// VIEW HOLDER CLASS
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView albumImageView;
TextView albumTextView;
public ViewHolder(@NonNull View itemView) {
super(itemView);
albumImageView = itemView.findViewById(R.id.iv_album_img);
albumTextView= itemView.findViewById(R.id.tv_album_name);
Log.i("ViewHolder","DataSet");
}
}
}
Деятельность Галереи
package com.udaan.recstudentportalV2;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.android.volley.Cache;
import com.android.volley.Network;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.cache.DiskBasedCache;
import com.android.volley.error.VolleyError;
import com.android.volley.request.StringRequest;
import com.android.volley.toolbox.BasicNetwork;
import com.android.volley.toolbox.HurlStack;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.udaan.recstudentportalV2.util.UrlManager;
public class Gallery extends AppCompatActivity {
UrlManager urlManager = new UrlManager();
RecyclerView albumrv;
ProgressBar p;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery);
// mTv=findViewById(R.id.test);
albumrv = findViewById(R.id.RV_main_Activity);
albumrv.setLayoutManager(new LinearLayoutManager(this));
p = findViewById(R.id.gal_p);
mGetAdminData();
}
protected void mGetAdminData() {
// final ProgressDialog progressDialog = new ProgressDialog(getApplicationContext());
// progressDialog.setMessage("Getting Albums...");
// progressDialog.show();
RequestQueue requestQueue;
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024);
Network network = new BasicNetwork(new HurlStack());
requestQueue = new RequestQueue(cache, network);
requestQueue.start();
String url = "https://example.com/gallery/getGalleryAlbum.php";
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("Gallery Response",response);
p.setVisibility(View.GONE);
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
Album[] album = gson.fromJson(response, Album[].class);
albumrv.setAdapter(new AlbumAdapter(getApplicationContext(), album));
Log.i("Gallery Response","Adapter set");
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast toast = Toast.makeText(getApplicationContext(), "Failed," + error.toString(), Toast.LENGTH_LONG);
toast.show();
}
});
requestQueue.add(stringRequest);
}
}
Пожалуйста, помогите, я потратил на это весь свой день, любая помощь будет отличной.