question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@HiltAndroidApp base class must extend Application error after update to Dagger Hilt 2.42

See original GitHub issue

When 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:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
bcorsocommented, May 17, 2022

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.

0reactions
kuanyingchoucommented, Aug 17, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found