【发布时间】:2018-10-31 20:34:18
【问题描述】:
我无法让 dagger 与 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);
}
}
因此,我的 Activity 类中存在相同的 Fragment 类型错误
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;
}
}
不适用
1.Material Design Components 说我不应该碰任何支持库。 (AndroidInjection.inject<android.support.v4.app.Fragment> 被消灭了,
虽然我的 Dagger 组件无法生成)。
2.Google says android.app.Fragment is depreciated.
我如何连接所有东西以使 dagger 与 androidx 命名空间一起工作。
问候, 乔治
【问题讨论】:
标签: android android-fragments dagger-2 dagger androidx