-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Description:
After upgrading our project to Gradle 8.5 and enabling minification in our modules, Hilt class generation fails. This results in missing bindings during the compilation process. The error points to missing @Provides-annotated methods, although these methods are correctly defined in the code.
Environment:
Gradle Version: 8.7
AGP Version: 8.5.1
Hilt Version: 2.51.1
ProGuard/R8: Enabled
R8 Version: 8.3.37
Steps to Reproduce:
Upgrade project to AGP 8.5.1.
Enable minification (ProGuard/R8) in build.gradle for the app and modules.
Build the project.
Expected Behavior:
Hilt should correctly generate all necessary classes and bindings during the build process.
Actual Behavior:
Compilation fails with the following error:
/Users/username/StudioProjects/projectname/app/build/generated/hilt/component_sources/developRelease/com/example/projectname/App_HiltComponents.java:443: error: [Dagger/MissingBinding] com.example.projectname.data.CardsProdRepository cannot be provided without an @Provides-annotated method.
public abstract static class SingletonC implements FragmentGetContextFix.FragmentGetContextFixEntryPoint,
ProGuard/R8 Configuration:
ProGuard rules have been added to preserve Hilt classes:
# Hilt
-keep class dagger.hilt.** { *; }
-keep @dagger.hilt.android.lifecycle.HiltViewModel class * { *; }
-keep @dagger.hilt.DefineComponent.Builder class * { *; }
-keep @dagger.hilt.migration.DisableInstallInCheck class * { *; }
# Module-specific rules
-keep class com.example.projectname.data.CardsProdRepository { *; }
-keep class com.example.projectname.** { *; }
Relevant Code Snippets:
Repository Module:
@Module
@InstallIn(ViewModelComponent::class)
object InternalDataCardsModule {
@Provides
@Reusable
internal fun providesProdRepository(
localSource: CardsLocalSource,
remoteSource: CardsRemoteSource,
cacheRequestDataSource: CacheRequestDataSource
): CardsProdRepository = CardsProdRepositoryImpl(localSource, remoteSource,cacheRequestDataSource)
}Build Configuration (module/build.gradle):
<img width="687" alt="Screenshot 2024-08-08 at 10 56 48" src="https://github.com/user-attachments/assets/05ae62ee-f0c9-4da8-8dfe-8284730fa835">
Workaround:
Disabling minification resolves the issue, but this is not a viable solution for production builds where minification is necessary.
Additional Context:
The error occurs across multiple modules that rely on Hilt for dependency injection.
The same configuration worked as expected prior to the upgrade to Gradle 8.5.
Thank you for your assistance.