Dagger with androidx namespace not working

Viewed 926

I cannot get dagger to work with androidx.fragment.app.Fragment;

// My dependencies
implementation 'com.google.android.material:material:1.0.0'
...
implementation 'com.google.dagger:dagger-android:2.19'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.19'

// gradle.properties
android.useAndroidX=true
android.enableJetifier=true

// In my Fragment
...
import androidx.fragment.app.Fragment;
...

public abstract class BaseFragment extends Fragment {

   @Override
    public void onAttach(Context context) {
        AndroidInjection.inject(this); // cannot resolve method here, AndroidInjection wants to use AndroidInjection.inject(android.app.Fragment);
        super.onAttach(context);        
    }
}

The same Fragment type error is present in my Activity class thus

public class MainActivity extends BaseActivity implements HasFragmentInjector{

    @Inject
    DispatchingAndroidInjector<androidx.fragment.app.Fragment> fragmentInjector;

// incompatible  return type here, AndroidInjector wants to use AndroidInjector<android.app.Fragment>
    @Override
    public AndroidInjector<Fragment> fragmentInjector() { 
        return fragmentInjector;
    }

}

N/B 1.Material Design Components says i should NOT touch any support libraries. (AndroidInjection.inject<android.support.v4.app.Fragment> gets dejetified, though my Dagger Component fails to generate).

2.Google says android.app.Fragment is depreciated.

How do i wire everything to have dagger work with androidx namespace.

Regards, George

1 Answers
Related