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.

Hilt - SingletonC build files generated for *each* unit test significantly impacting unit test build times

See original GitHub issue

After having migrated our codebase from a pure Dagger 2 implementation to a Hilt-enabled one, we noticed a significant impact in build times for unit tests.

After some investigation into the matter we noticed that there are _HiltComponents_SingletonC.java-suffixed files created for every single unit test that has been enabled for Hilt usage… All files have the same size and content, which seems to indicate that the same SingletonC class is being recreated and packaged as a build artifact for all Hilt-enabled unit tests.

Having removed these in another branch, we were able to also confirm that a significant amount of the increase in build time we had noticed can be attributed to the proliferation of these files…

Is there something we’re missing with our implementation?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
bcorsocommented, Apr 16, 2021

@snepalnetflix, see the Dagger 2.34 release notes for details on the -Adagger.hilt.shareTestComponents flag.

Also, see the docs for how to enable the flag and expected issues you might hit when trying to enable it.

1reaction
bcorsocommented, Mar 3, 2021

@mhernand40 thanks for the extra info.

0 usages of @UninstallModules and @BindsValue @TestInstallIn already being used.

That’s great! This is the first use case we’re going to optimize for. All of your tests should be able to share a single component, which should hopefully bring your build times back down to where they were before.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hilt testing guide | Android Developers
Note: As Hilt creates new components for tests that use @UninstallModules , it can significantly impact unit test build times. Use it when...
Read more >
Android Tests failing when using Hilt caused by ...
I had the same Problem, while Testing i got a ClassCastException: HiltTestApplication cannot be cast to AbcApp (my Application class).
Read more >
Testing with Hilt android - Nyame Bismark - Medium
As Hilt creates new components for tests that use @UninstallModules , it can significantly impact unit test build times. Use it when necessary...
Read more >
A Deep Dive into Unit Testing - Semaphore CI
Testing is a significant part of software development, and unit tests are fundamental. Learn how unit testing can help you improve code ...
Read more >
Android — Instrumentation test with hilt | Mahendran
Testing strategy · Unit tests: Small & fast. Even with a large number of tests, there won't be much impact on execution time....
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