Stop accessing non-public fields in Fragment
See original GitHub issueAfter updating the support library of my project to the new AndroidX scheme, the app started crashing after calling this method: BackstackAccessor.isFragmentOnBackStack(Fragment())
Crash:
java.lang.IllegalAccessError: Method 'boolean androidx.fragment.app.Fragment.isInBackStack()' is inaccessible to class 'androidx.core.app.BackstackAccessor'
After some investigation, I found that the issue is this file: https://github.com/sockeqwe/mosby/blob/master/utils-fragment/src/main/java/android/support/v4/app/BackstackAccessor.java which is accessing a non-public field by “faking” the package.
As well as being a bad practice, this stops working after migrating to AndroidX due to the change of package names.
Ideally this should be reverted to the commented-out version of the code still existing in the linked file.
Issue Analytics
- State:
- Created 5 years ago
- Comments:25 (13 by maintainers)
Top GitHub Comments
AndroidX is now stable 1.0.0. Even more, Google wrote that the Support 28.0.0 is the last version that supports
android.support
package. It is time to move on.As a temporary workaround until then for those who want to continue using AndroidX, you can exclude the
utils-fragment
module dependency in yourbuild.gradle
:and then define your own
androidx.core.app.BackstackAccessor
class: