未创建DaggerAppComponent [英] DaggerAppComponent not created
问题描述
使用匕首2.10以前,我可以通过这样做来创建应用程序组件
With dagger 2.10 I used to be able to create the app component by doing
sAppComponent = DaggerAppComponent.builder()
.appModule(new AppModule(this))
.sessionModule(new SessionModule())
.netModule(new NetModule())
.dataModule(new DataModule())
.build();
我已经在使用AndroidInjector进行活动了,一切都很好. 现在,我切换到2.11,但找不到创建应用程序组件的方法. 在 Google教程中,我看到:
I was already using the AndroidInjector for Activities and everything was fine. Now I switched to 2.11 and I can't find the way to create the app component. In the google tutorial I see:
DaggerYourApplicationComponent.create()
.inject(this);
要添加到应用程序的onCreate中.
就我而言,DaggerYourApplicationComponent = DaggerAppComponent
.问题在于不再创建DaggerAppComponent类.
to be added in the onCreate of the Application.
In my case DaggerYourApplicationComponent = DaggerAppComponent
. The problem is that DaggerAppComponent class isn't created anymore.
我有:
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文件中,我有:
in the build.gradle file I have:
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.27时,我从 Google教程复制了build.gradle
部分依赖项:
Ok Sorry for the noise. My silly mistake: when I switched to 2.27 I copied the build.gradle
section from the google tutorial where the dependency:
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVer"
未列出是出于我不知道的原因. 使用下面列出的依赖项,一切正常:
isn't listed for a reason I don't know. With the dependencies listed below everything works:
def daggerVer = 2.27 // or latest version
implementation "com.google.dagger:dagger:$daggerVer"
implementation "com.google.dagger:dagger-android-support:$daggerVer"
annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVer"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVer"
如果您使用的是Kotlin
If you are using Kotlin
apply plugin: 'kotlin-kapt'
dependencies {
def daggerVer = 2.27 // or latest version
implementation "com.google.dagger:dagger:$daggerVer"
implementation "com.google.dagger:dagger-android-support:$daggerVer"
kapt "com.google.dagger:dagger-android-processor:$daggerVer"
kapt "com.google.dagger:dagger-compiler:$daggerVer"
}
您可以在此处找到最新版本号.
You can find the latest release number here.
这篇关于未创建DaggerAppComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!