我在我的应用程序中使用匕首2。现在我不断面临以下错误。
Error:(14, 1) error: @com.example.hp.daggerdemoexample.scope.UserScope com.example.hp.daggerdemoexample.component.ServerComponent depends on more than one scoped component:
@Singleton com.example.hp.daggerdemoexample.component.NetworkComponent
@Singleton com.example.hp.daggerdemoexample.component.DatabaseManagerComponent
以下是我的组件类
ServerComponent.java
@UserScope
@Component(dependencies = {NetworkComponent.class, DatabaseManagerComponent.class}, modules = ServerModule.class)
public interface ServerComponent extends NetworkComponent, DatabaseManagerComponent {
void inject(MainActivity mainActivity);
void inject(RecyclerViewFragment mainActivity);
}
NetworkComponent.java
@Singleton
@Component (modules={ApplicationModule.class, NetworkCallModule.class})
public interface NetworkComponent {
Retrofit retrofit();
OkHttpClient okHttpClient();
}
DatabaseManagerComponent.java
@Singleton
@Component (modules = DatabaseManagerModule.class)
public interface DatabaseManagerComponent {
DBFlowHelper dbFLow();
}
UserScope.java
@Scope
public @interface UserScope {
}
和ApplicationData类
ApplicationData.java
public class ApplicationData extends Application {
private NetworkComponent mNetComponent;
private ServerComponent mServerComponent;
private DatabaseManagerComponent mDatabaseManagerComponent;
@Override
public void onCreate() {
super.onCreate();
FlowManager.init(this);
mNetComponent = DaggerNetworkComponent.builder()
.applicationModule(new ApplicationModule(this))
.networkCallModule(new NetworkCallModule("https:XXXXXXXX"))
.build();
mDatabaseManagerComponent = DaggerDatabaseManagerComponent.builder()
.databaseManagerModule(new DatabaseManagerModule())
.build();
mServerComponent = DaggerServerComponent.builder()//Error in this line due to ServerComponent Class DaggerServerComponent
.networkComponent(mNetComponent)
.databaseManagerComponent(mDatabaseManagerComponent)
.serverModule(new ServerModule())
.build();
}
public DatabaseManagerComponent getDatabaseManagerComponent(){
return mDatabaseManagerComponent;
}
public NetworkComponent getNetworkComponent(){
return mNetComponent;
}
public ServerComponent getServerComponent(){
return mServerComponent;
}
}
帮助我解决这个问题。
先谢谢