-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null dependency after migrating from Dagger to Hilt #3513
Comments
This is very strange, its as if Hilt produced a bad metadata class and thus fails to read it at the root, if we can find the which metadata class was wrongly produced we might be able to better understand the issue. Ideally creating a sample repro would be amazing, but I can see that being hard, and since sharing your project is not possible my other suggestion to you would be to attach a debugger to Hilt to try and figure out the issue. This comment has some instructions but I'll try to add to them.
That's it for now! Hopefully this will help you discover which metadata file is causing the crash. Note that once you find the type element you can further inspect the source and the originating |
@danysantiago I was able to attach a debugger over the weekend. The findings are very strange to me:
That's where I'm now. I don't want to move every class that's failing - it'd take too long. Even more bizarre are two things:
I tried debugging to find the difference between when the activity returns null and when it gives a correct result. It seems that it comes down to Please let me know if you have any ideas what can be causing this issue. If you have any additional questions or need me to debug/change something more, I'm happy to help. |
I have a few more questions:
The issue is definitely due to some cross-module classpath issue, i.e. while compiling |
As to 5: Turning this option off seems to fix the issue. I was able to receive meaningful errors again and fix them. The whole project compiles now. But I don't understand why it worked. What's more, it works only with all hilt modules in the main app module - when I tried to move hilt modules back to separate android modules, it started giving nulls again. So it seems like turning off this option only fixes activities and fragments. |
…t be found. Issue #3513. RELNOTES=n/a PiperOrigin-RevId: 468058866
…t be found. Issue #3513. RELNOTES=n/a PiperOrigin-RevId: 468071610
I submitted a change to improve the error message from that NPE to give us more information. Can you try running with Dagger from the head snapshots and try again? https://dagger.dev/dev-guide/versions has info on using the head snapshots. |
@Chang-Eric I tried to do it, but somehow it downloads dagger 2.28.3. Should it work with hilt the same way as in the docs you provided? Gradle Dependencies show
But previously I was able to determine with dependencies were problematic with the help of debugger, so this commit is an improvement for the future, not a solution to my problem at hand - I still don't know why
@danysantiago Any ideas what can be the issue here or how to debug it further? I can try again to rebuild my project from scratch adding classes as I go and waiting for it to finally give me the same error, but it will take a lot of time. |
@domhys, did you follow the last part of https://dagger.dev/dev-guide/versions:
|
I did, but I must've pasted it in the wrong build.gradle file. It's working correctly now - it prints which module has problems.
But as I said before - it doesn't solve my original problem. I still cannot migrate to Hilt because of these errors that I described in earlier comments. So I have to ask again: @bcorso @danysantiago Any ideas what can be the issue here or how to debug it further? I can try again to rebuild my project from scratch adding classes as I go and waiting for it to finally give me the same error, but it will take a lot of time. |
If One solution you could try is to add that dependency directly to your application. So, first find out which gradle library |
@bcorso that's the problem - |
Sorry, I'm not asking you to take the hilt modules out of the android modules they're currently in. I'm asking if you can try adding the android module as a direct dependency to your main app module by including it in the "dependencies" section of the |
@bcorso It already is included.
The modules configuration didn't change at all between dagger and hilt implementations. |
Sorry, I don't really have any other ideas without being able to look into it myself. If you could provide a sample project with repro steps that would help a lot (I realize this is difficult, but not really seeing any other option here). |
@bcorso @danysantiago I was able to create a small example that reproduces this issue: https://github.com/domhys/hiltTest I started building this app from scratch adding new things waiting for the error message. I noticed that one external library was causing this error: However, that's not all. I experimented with changing package name of the app and found out that when I change the first part, the error also goes away even with the external library included. I've created a
|
Thanks for the repro project @domhys! The TL:DR is that your project is running into some sort of JDK or Android Gradle Plugin (AGP) bug and this is not an issue specific to Hilt. Indeed the library The following processor simply tries to find your
When configured to run with kapt:
When debugging, deep in the JDK sources I see it insteads find a
The API that Hilt uses That's as far as I was able to analyze the issue, which means this is an issue with that library, maybe because it is already obfuscated or maybe it's an issue with the jetifier, but it seems the library has not migrated to androidx which means you need the jetifier enabled so I was not able to confirm a workaround, it could also be a JDK bug so maybe trying using a newer JDK other than 11, but you might run into some other trouble... As for the package names, as you have already discovered if you change your package to not be prefixed with one of the many possible root classes the jar contains then you'll avoid the issue since the compiler won't get confused when finding the type elements. I don't think there much Hilt can do here (sorry!), I would try to update the project to remove Hilt and just have a simple processor (like the one above) that demonstrates the issue and share it with the AGP team. |
I'm doing a migration from Dagger (with dagger-android) to Hilt. After completing all the steps from the migration guide, I'm getting a Null dependency error during compilation (full stacktrace at the end). At this point I'm not able to obtain any meaningful error message so I've got no idea what to fix.
What I've tried to do:
My setup: As this is a proprietary software, I'm not able to share the full source code, but my setup is pretty standard:
kapt "com.google.dagger:hilt-compiler:2.43.1" in all modules (tried different versions as well - 2.40.5 and 2.42)
As I don't have any idea what causes this issue, I don't know which parts of my code can be useful to track down this bug (but I'm happy to answer any questions relating to my setup).
I'm aware that this is a hard bug to track down without any source code, but I'm posting for two reasons:
The text was updated successfully, but these errors were encountered: