在尝试集成最新的匕首2版本时,我面临着匕首自动生成的问题。Dagger并不是自动生成DaggerAppComponent,尽管有几次重新构建和使模块应用程序过程。
应用程序类:
public class BaseApplication extends Application
{
private AppComponent appComponent;
@Override
public void onCreate()
{
super.onCreate();
initAppComponent();
}
private void initAppComponent()
{
DaggerAppComponent.builder()
.appModule(new AppModule(this))
.build();
}
public AppComponent getAppComponent()
{
return appComponent;
}
}
AppComponent
@Singleton
@Component(modules = AppModule.class)
public interface AppComponent
{
void inject(BaseApplication application);
}
AppModule:
@Module
public class AppModule
{
private BaseApplication application;
public AppModule(BaseApplication app)
{
application = app;
}
@Provides
@Singleton
Context provideContext()
{
return application;
}
@Provides
Application provideApplication()
{
return application;
}
}
使用的依赖项:
compile 'com.google.dagger:dagger-android:2.11'
compile 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
androidTestCompile 'com.google.code.findbugs:jsr305:3.0.1'
在这方面的任何帮助都将受到高度赞赏。
发布于 2017-07-22 14:51:43
似乎我使用了错误的依赖关系:
compile 'com.google.dagger:dagger-android:2.x'
compile 'com.google.dagger:dagger-android-support:2.x' // if you use the support libraries
annotationProcessor 'com.google.dagger:dagger-android-processor:2.x'
如果在dagger.android中使用类,则应使用上述依赖项。
正确的依赖关系是:
compile 'com.google.dagger:dagger:2.x'
annotationProcessor 'com.google.dagger:dagger-compiler:2.x'
发布于 2018-11-25 18:10:50
你需要这两条线
implementation 'com.google.dagger:dagger:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
当使用kotlin时,使用kapt而不是annotationProcessor。生成的类,如Dagger+AppComponentClass,例如:DaggerAppComponent
发布于 2017-11-02 22:50:07
为Java项目添加下面的依赖项解决了问题
annotationProcessor 'com.google.dagger:dagger-compiler:2.27'
对于Kotlin项目(在添加kotlin-kapt
之后):
kapt "com.google.dagger:dagger-compiler:2.27"
https://stackoverflow.com/questions/45251222
复制相似问题