@HiltAndroidApp base class must extend Application error after update to Dagger Hilt 2.42
See original GitHub issueWhen update hilt version 2.41 to 2.42 fails build with error message.
~/g/g/s/dagger-2.42-libapplication ❯❯❯ ./gradlew installDebug
Configuration on demand is an incubating feature.
> Task :app:hiltJavaCompileDebug FAILED
error: [Hilt]
@HiltAndroidApp base class must extend Application. Found: com.example.mylibrary.Hilt_MyApplication
[Hilt] Processing did not complete. See error above for details.
1 error
FAILURE: Build failed with an exception.
This project has Application class into library module (not application module).
// success 2.41, but failed 2.42
// define into library module
@HiltAndroidApp
class MyApplication : Application()
If This Application class move to application module, the build will succeed.
// application module
@HiltAndroidApp
class MyApplication : Application()
it’s expected behavior on 2.42?
sample project: https://github.com/satoshun-android-example/dagger-2.42-libapplication
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
Dagger-hilt error while compiling project - Stack Overflow
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.42' ... Looks like Dagger needs to update the kotlin-metadata-jvm library to 0.4.0 ...
Read more >Gradle Build Setup - Dagger
To use Hilt, add the following build dependencies to the Android Gradle module's ... Without the Gradle plugin, the base class must be...
Read more >Hilt: No JaCoCo test coverage on @AndroidEntryPoint classes.
Unzip and check the project out in android studio. Run gradle clean app:jacocoTestReportDebug . Open $projectDir/build/reports/jacoco/jacocoTestReportDebug/html ...
Read more >Dependency Injection with Dagger 2 - CodePath Cliffnotes
Many Android apps rely on instantiating objects that often require other ... public class MainActivity extends Activity { @Inject MyTwitterApiClient ...
Read more >Hilt testing guide | Android Developers
Hilt isn't necessary for unit tests, since when testing a class that uses ... If your tests need a different base application, see...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @satoshun, Thanks for reporting this.
You’re right that the Hilt application class must be located in the Gradle application module when you’re using the Hilt Gradle plugin.
As for why your build started failing when upgrading to 2.42, I’m not sure. However, due to the mechanics of the Hilt Gradle plugin it’s not something that we can really guarantee will work except at the Gradle application module level, so you should definitely move it.
I’ll update the documentation to make this explicit.
We can also look into automating this check so that it will automatically detect and fail when the application class is not defined in the Gradle application module.
A more explicit error message will be included in the next release when an Application annotated with @HiltAndroidApp is not defined in an application module. Closing this one.