I want to use two different backend in my android application with different response format, i am using hilt as dependency injection with retrofit for network calling, which is great to work on.
as i have added my 2nd server network files and in app module, its giving me error which is listed at the end.
i need to know a way out in this situation without making any prominent architecture changes.
@Keep
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
@Singleton
@Provides
fun provideRetrofit(gson: Gson,@ApplicationContext appContext: Context): Retrofit = Retrofit.Builder()
.client(
OkHttpClient().newBuilder()
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).readTimeout(80,TimeUnit.SECONDS)
.addInterceptor(
ChuckerInterceptor.Builder(appContext)
.collector(ChuckerCollector(appContext))
.maxContentLength(250000L)
.redactHeaders(emptySet())
.alwaysReadResponseBody(false)
.build()
)
.build()
)
.baseUrl(UtilSingleton.instance!!.GetBaseUrl())
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
@Provides
fun provideGson(): Gson = GsonBuilder().create()
@Provides
fun providePostsService(retrofit: Retrofit): ApiService =
retrofit.create(ApiService::class.java)
@Singleton
@Provides
fun provideApiRemoteDataSource(apiService: ApiService) = ApiRemoteDataSource(apiService)
@Singleton
@Provides
fun provideRepository(
remoteDataSource: ApiRemoteDataSource
) =
MainRepo(remoteDataSource)
/**----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------**/
@Singleton
@Provides
fun provideRetrofitEmall(gson: Gson,@ApplicationContext appContext: Context): Retrofit = Retrofit.Builder()
.client(
OkHttpClient().newBuilder()
.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).readTimeout(80,TimeUnit.SECONDS)
.addInterceptor(
ChuckerInterceptor.Builder(appContext)
.collector(ChuckerCollector(appContext))
.maxContentLength(250000L)
.redactHeaders(emptySet())
.alwaysReadResponseBody(false)
.build()
)
.build()
)
.baseUrl(UtilSingleton.instance!!.GetBaseUrl())
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
@Provides
fun providePostsServiceEmall(retrofit: Retrofit): EmallApiService =
retrofit.create(EmallApiService::class.java)
@Singleton
@Provides
fun provideApiRemoteDataSource(apiService: EmallApiService) = EmallApiRemoteDataSource(apiService)
@Singleton
@Provides
fun provideRepository(
remoteDataSource: EmallApiRemoteDataSource
) =
EmallRepo(remoteDataSource)
}
Build Error ->
Execution failed for task ':app:kaptLocalDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
Full Log ->
D:\vaultsNew\vaultspaynewapis\app\build\tmp\kapt3\stubs\localDebug\com\uae\myvaultspay\di\AppModule.java:40: error: Cannot have more than one binding method with the same name in a single module
public final com.uae.myvaultspay.data.remote.ApiRemoteDataSource provideApiRemoteDataSource(@org.jetbrains.annotations.NotNull()
^D:\vaultsNew\vaultspaynewapis\app\build\tmp\kapt3\stubs\localDebug\com\uae\myvaultspay\di\AppModule.java:78: error: Cannot have more than one binding method with the same name in a single module
public final com.uae.myvaultspay.data.remote.emallremote.EmallApiRemoteDataSource provideApiRemoteDataSource(@org.jetbrains.annotations.NotNull()
^D:\vaultsNew\vaultspaynewapis\app\build\tmp\kapt3\stubs\localDebug\com\uae\myvaultspay\di\AppModule.java:48: error: Cannot have more than one binding method with the same name in a single module
public final com.uae.myvaultspay.data.repository.MainRepo provideRepository(@org.jetbrains.annotations.NotNull()
^D:\vaultsNew\vaultspaynewapis\app\build\tmp\kapt3\stubs\localDebug\com\uae\myvaultspay\di\AppModule.java:86: error: Cannot have more than one binding method with the same name in a single module
public final com.uae.myvaultspay.data.repository.EmallRepo provideRepository(@org.jetbrains.annotations.NotNull()
^warning:
File for type 'com.uae.myvaultspay.MyApplication_HiltComponents' created
in the last round will not be subject to annotation processing.
Execution failed for task ':app:kaptLocalDebugKotlin'.
> A failure occurred while executing
org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)