匕首2.10我曾經是能夠通過我已經使用AndroidInjector的活動和一切都很好做DaggerAppComponent沒有創建
sAppComponent = DaggerAppComponent.builder()
.appModule(new AppModule(this))
.sessionModule(new SessionModule())
.netModule(new NetModule())
.dataModule(new DataModule())
.build();
創建應用程序組件。 現在我切換到2.11,我無法找到創建應用程序組件的方式。 在google tutorial我看到:
DaggerYourApplicationComponent.create()
.inject(this);
在應用程序的OnCreate添加。 在我的情況下,DaggerYourApplicationComponent = DaggerAppComponent
。問題是DaggerAppComponent類不再被創建。
我:
public class App extends android.support.multidex.MultiDexApplication implements HasActivityInjector {
@Inject DispatchingAndroidInjector<Activity> mDispatchingActivityInjector;
@Override
public void onCreate() {
super.onCreate();
sAppComponent = DaggerAppComponent.create().inject(this); //here the error
和:
@Singleton
@Component(modules = {
AppModule.class,
MainActivityModule.class,
...
})
public interface AppComponent {
void inject(App app);
...
}
中的build.gradle文件我有:
def daggerVer = 2.11
compile "com.google.dagger:dagger:$daggerVer"
compile "com.google.dagger:dagger-android-support:$daggerVer"
annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVer"
在清單中,並在註冊應用程序類? –
是的,應用程序工作正常與版本2.10 – kingston
而不是嘗試'DaggerAppComponent.builder()。創建(this).inject(this)'。 – azizbekian