I'm trying to use this class. It works fine on debug builds but It never works on release builds. I know that proguard removes it, so the question is How to keep that class?
import android.support.design.internal.BottomNavigationItemView;
import android.support.design.internal.BottomNavigationMenuView;
import android.support.design.widget.BottomNavigationView;
import android.util.Log;
import java.lang.reflect.Field;
public class BottomNavigationViewHelper {
public static void disableShiftMode(BottomNavigationView view) {
BottomNavigationMenuView menuView = (BottomNavigationMenuView) view.getChildAt(0);
try {
Field shiftingMode = menuView.getClass().getDeclaredField("mShiftingMode");
shiftingMode.setAccessible(true);
shiftingMode.setBoolean(menuView, false);
shiftingMode.setAccessible(false);
for (int i = 0; i < menuView.getChildCount(); i++) {
BottomNavigationItemView item = (BottomNavigationItemView) menuView.getChildAt(i);
//noinspection RestrictedApi
item.setShiftingMode(false);
// set once again checked value, so view will be updated
//noinspection RestrictedApi
item.setChecked(item.getItemData().isChecked());
}
} catch (NoSuchFieldException e) {
Log.e("BNVHelper", "Unable to get shift mode field", e);
} catch (IllegalAccessException e) {
Log.e("BNVHelper", "Unable to change value of shift mode", e);
}
}
}
-keepclassmembernames. This is the most permissive keep directive; it lets ProGuard do almost all of its work. Unused classes are removed, the remaining classes are renamed, unused members of those classes are removed, but then the remaining members keep their original names.
Shrinking Options Specifies not to shrink the input. By default, ProGuard shrinks the code: it removes all unused classes and class members. It only keeps the ones listed by the various -keep options, and the ones on which they depend, directly or indirectly.
R8 configuration files. R8 uses ProGuard rules files to modify its default behavior and better understand your app's structure, such as the classes that serve as entry points into your app's code.
R8 is another tool that will convert your java byte code into an optimized format of dex code. It will check the whole application and will remove the unused classes and methods. It helps us to reduce the size of our APK and to make our app more secure. R8 uses similar proguard rules to modify its default behavior.
This did the trick for me.
# Bottom Navigation Helper
-keep class android.support.design.internal.BottomNavigationItemView{ *; }
-keep class android.support.design.internal.BottomNavigationMenuView{ *; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With