I want to inject my Androidx fragments using dagger 2. In my activity I have:
public class MainActivity extends AppCompatActivity implements HasSupportFragmentInjector
{
@Inject Reposetory reposetory;
@Inject DispatchingAndroidInjector<androidx.fragment.app.Fragment> dispatchingAndroidInjector;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public AndroidInjector<androidx.fragment.app.Fragment> supportFragmentInjector()
{
return dispatchingAndroidInjector;
}
}
the problem is when i want to build the project i get this error:
error: cannot find symbol class MapBuilder
and when i change androidx.fragment.app.Fragment to Fragment in DispatchingAndroidInjector i don't get this error any more.
as was suggested before, add the below code to your gradle.properties
And if you are trying to inject into a Fragment you have to replace
AndroidInjection.inject(this)
withAndroidSupportInjection.inject(this)
Dagger supports were missing for AndroidX. It is added for version 2.21 and above
So you can use it as -
If jetifier does not change support packages to androidx packages. You can download
jetifier
tool from here and convert the android-dagger-support.aar file manually by using the following command.Then add the library to your project. This is the HasSupportFragment class after conversion
Androidx is not supported yet, but enabling jetifier maybe solve your problem.
Just add the below code to your
gradle.properties
Also see these issues for detail:
migration to androidx library
AndroidInjection support for androidx Fragment