eltos / SimpleDialogFragments

An Android library to create dialogs with ease and handle user interaction reliably, using fragments and material design.
Apache License 2.0
119 stars 17 forks source link

Default TAG for results is unreliable #41

Closed eltos closed 6 years ago

eltos commented 6 years ago

When showing a Dialog without passing an explicit TAG, the implementation tries to use the TAG field as default (See show(Fragment fragment) and show(FragmentActivity activity) in SimpleDialog.java):

try {
    tag = (String) this.getClass().getField("TAG").get(null);
} catch (Exception ignored) { }

This is unreliable and fails if the code was minified, which is common practice for android apps during release build (e.g. minifyEnabled true in build.gradle). The bug is particularly insidious, as it will not occur for debug builds where minification is disabled by default.

eltos commented 6 years ago

Note:
The "default TAG behaviour" is not (yet) documented in the javadocs. These state that the OnDialogResultListener will never be called with these show functions.

eltos commented 6 years ago

Solution: In your proguard-rules.pro add:

-keepclassmembers class * extends eltos.simpledialogfragment.SimpleDialog {
    public static final java.lang.String TAG;
}

This prevents proguard to rename the filed during minification.