After upgrading to AGP 8.4 I’ve faced a lot of build issues for the release build, mainly to do with R8 library keep rules.
But now I’ve stumbled upon another issue:
MyApplication_HiltComponents.java:382: error: [Dagger/DuplicateBindings] kotlinx.coroutines.CoroutineDispatcher is bound multiple times:
public abstract static class SingletonC implements MyApplication_GeneratedInjector,
^
@Provides @Singleton kotlinx.coroutines.CoroutineDispatcher com.myapp.repo.DispatcherModule.providesDefaultDispatcher()
@Provides @Singleton kotlinx.coroutines.CoroutineDispatcher com.myapp.repo.DispatcherModule.providesIoDispatcher()
@Provides @Singleton kotlinx.coroutines.CoroutineDispatcher com.myapp.repo.DispatcherModule.providesMainDispatcher()
The Hilt module and annotations:
@Module
@InstallIn(SingletonComponent::class)
object DispatcherModule {
@DefaultDispatcher
@Provides
@Singleton
fun providesDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default
@IoDispatcher
@Provides
@Singleton
fun providesIoDispatcher(): CoroutineDispatcher = Dispatchers.IO
@MainDispatcher
@Provides
@Singleton
fun providesMainDispatcher(): CoroutineDispatcher = Dispatchers.Main
}
}
@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class IoDispatcher
@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class DefaultDispatcher
@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class MainDispatcher
the rules I added for the module and anotations:
-keep public class com.myapp.** { public *; }
-keep, allowobfuscation public class com.myapp.**ModuleKt
-keep, allowobfuscation public class com.myapp.**EntryPointKt
-keepnames class * extends android.os.Parcelable
-keepnames class * extends java.io.Serializable
-keep class com.myapp.repo.DispatcherModule*
I am pretty sure it’s still related to R8 somehow. The debug build works fine
I tried:
- upgrading hilt to 1.2.0,
- adding
android.disableMinifyLocalDependenciesForLibraries=true
togradle.properties
- adding class specific keep rules, general keep rules,
@Keep
anotations on each class and@Provide
method