Reputation: 3061
I'm new to dagger and I'm studding it with small app for android. I'm trying to use Retrofit for REST request over http and https to two servers (dev and prod). So I have module in debug flavour where :
@dagger.Module(overrides = true, library = true, complete = false)
public class DebugApiModule {
private static final String SRV = "dev.mysrv.com";
private static final String HTTP = "http://";
private static final String HTTPS = "https://";
public static final String API_URL = HTTP + SRV;
public static final String API_URL_SECURE = HTTPS + SRV;
@Provides @Singleton @Api String provideApi() { return API_URL; }
@Provides @Singleton @ApiSecure String provideApiSecure() { return API_URL_SECURE; }
}
Here I'm using annotation in order to differ two strings but I get error:
Error:(23, 50) error: Duplicate bindings for java.lang.String in override module(s) - cannot override an override:
com.myapp.common.api.DebugApiModule.provideApi()
com.myapp.common.api.DebugApiModule.provideApiSecure()
what's wrong with this code ?
Upvotes: 0
Views: 2971
Reputation: 76125
Both the @Api
and @ApiSecure
annotations need to be annotated with javax.inject.Qualifier
in order for Dagger to use them as a differentiating factor.
@Qualifier
@Retention(RUNTIME)
public @interface Api {
}
Upvotes: 2