NavDirection cast issue since I have upgraded to gradle 4.2.0

Viewed 81

I have upgraded my project to

classpath 'com.android.tools.build:gradle:4.2.0'

I have a static method in a utils File :

public static void launchFragment(BaseFragment fragment, NavDirections directions) {
    NavHostFragment.findNavController(fragment).navigate(directions);
}

Since this morning if I'm using

 ActivityUtils.launchFragment(this, ProfileFragmentDirections.accountAction());

It's good but if I'm calling an action with parameters like this one

   ActivityUtils.launchFragment(this, MainHostFragmentDirections.webAction(getString(R.string.info_moderation), WebFragment.MODERATION));

I have an error on the IDE

Cannot resolve method 'launchFragment(fr.tmly.androidapp.ui.main.activity.MainActivity, fr.tmly.androidapp.ui.main.fragment.MainHostFragmentDirections.@androidx.annotation.NonNull WebAction)'

The error say that

fr.tmly.androidapp.ui.main.fragment.MainHostFragmentDirections.@androidx.annotation.NonNull WebAction

is not a NavDirections class, but I can build compile and run the project and if I check in debugger

good type as you can see it's an instance of NavDirection

The solution to get ride of this error is to add (NavDirections) cast like this

ActivityUtils.launchFragment(this, (NavDirections) MainHostFragmentDirections.webAction(
                        getString(R.string.info_moderation), WebFragment.MODERATION));

But I'm using this method everywhere in My app and I dont want to add the manual cast everywhere, what can I do ? Before the gradle upgrade I haven't this error.

0 Answers
Related