I am having a hard time learning proguard and I need help to remove all the R8 warnings and properly implement the proguard rules. I had watched mostly all the videos on youtube and read blogs, documentation, and articles about proguard / proguard-rules but so far I still have many questions right now, I will enumerate all of it. Here are my questions:
- So far I know that when I created model classes I need to add a
-keep class
to the package so it will not be obfuscated, but how about a model just like this: (Should I also add-keep
on the proguard-rules?)
public class Constants {
public static final int ERROR_DIALOG_REQUEST = 9001;
public static final int PERMISSIONS_REQUEST_ENABLE_GPS = 9002;
public static final int PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 9003;
public static final String LOG_DB = "DB_Error";
}
//Or like this:
public class CameraView extends SurfaceView implements SurfaceHolder.Callback {
public CameraView(Context context) {
super(context);
getHolder().addCallback(this);
setFocusableInTouchMode(true);
setFocusable(true);
requestFocus();
}
@Override
public void surfaceCreated(SurfaceHolder holder) { }
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { }
@Override
public void surfaceDestroyed(SurfaceHolder holder) { }
}
How about the Adapter Classes like
RecyclerAdapter
orFirestorePagingAdapter
? I know that they will get affected by the obfuscation but should we just let it obfuscated? or should we also add it to the rules?The same goes for Activity Classes what are the necessary things to do? Will it affect the process if I retrieve data from the database for example?
Next is about the library. I know that I should add the corresponding proguard rules in every dependency but I saw some blog that said it needs to add OkHttp3 even though he didn't add the implementation to his dependencies. So I came up with a question of how should I know if there are also other libraries that are needed to add to the rules?
Lastly, how should I debug my rules or how should I know if ever I included or missing some rules in proguard? (If possible, Can you give some example on debugging the proguard-rules)
Hope you can answer all of my questions because I am pretty sure that someone out there is struggling on proguard too so I hope that if they saw these questions it will help them overcome this kind of situation without having a hard time finding answers on the internet separately. Thank you!