Allow obfuscation of `androidx.lifecycle.ReportFragment`
* `androidx.lifecycle` still intentionally depends on the deprecated `android.app.Fragment` to avoid creating a dependency with `androidx.fragment`.
* `androidx.lifecycle.ReportFragment` remains necessary for the Lifecycle Runtime, which causes problems when minification is enabled.
* This new rule mirrors the rules applied to `androidx.fragment.Fragment`, enabling obfuscation of the deprecated `android.app.Fragment` EXCLUSIVELY for `ReportFragment`. This guarantees that `ReportFragment` won't cause issues, and the Proguard rule will function exactly as the new `Fragment` library does.
* Alternatively, we could mirror the `androidx.fragment` rule in the future to ensure consistent minification of any `Fragment` extending `android.app.Fragment`. However, this change would likely belong in a different artifact, rather than within `lifecycle-runtime`.
Fixes: b/338958225
Fixes: b/341537875
Test: manual
(cherry picked from https://android-review.googlesource.com/q/commit:ab7690c74e67844b84714a9e062d603ec5038094)
Merged-In: I6e08bb7cdaf41b73100929169780da074ea48832
Change-Id: I6e08bb7cdaf41b73100929169780da074ea48832
diff --git a/lifecycle/lifecycle-runtime/proguard-rules.pro b/lifecycle/lifecycle-runtime/proguard-rules.pro
index 95192c1..4335578 100644
--- a/lifecycle/lifecycle-runtime/proguard-rules.pro
+++ b/lifecycle/lifecycle-runtime/proguard-rules.pro
@@ -15,6 +15,12 @@
@androidx.lifecycle.OnLifecycleEvent *;
}
+# The deprecated `android.app.Fragment` creates `Fragment` instances using reflection.
+# See: b/338958225, b/341537875
+-keepclasseswithmembers,allowobfuscation public class androidx.lifecycle.ReportFragment {
+ public ();
+}
+
# this rule is need to work properly when app is compiled with api 28, see b/142778206
# Also this rule prevents registerIn from being inlined.
--keepclassmembers class androidx.lifecycle.ReportFragment$LifecycleCallbacks { *; }
\ No newline at end of file
+-keepclassmembers class androidx.lifecycle.ReportFragment$LifecycleCallbacks { *; }