java.util.NoSuchElementException with Dagger 2.27
See original GitHub issueJust tried upgrading our app to Dagger 2.27 and removed all JvmStatic
annotations and get this internal error in compilation. Dagger expects something to be available but it is not. The error message does not really give any information.
Let me know how I can provide more information. Thanks
> Task app:kaptDebugAndroidTestKotlin FAILED
e: [kapt] An exception occurred: java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at dagger.internal.codegen.bindinggraphvalidation.IncompatiblyScopedBindingsValidator.lambda$visitGraph$1(IncompatiblyScopedBindingsValidator.java:74)
at java.util.Optional.ifPresent(Optional.java:159)
at dagger.internal.codegen.bindinggraphvalidation.IncompatiblyScopedBindingsValidator.visitGraph(IncompatiblyScopedBindingsValidator.java:71)
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:18 (2 by maintainers)
Top Results From Across the Web
Android build fails when using dagger 2.18 with kotlin kapt
I have added all the required dependencies but upon building my project I am getting the below error. [kapt] An exception occurred: java.util....
Read more >Introduction to Dagger 2: For Beginners | Medium
This error occurs because dagger does not know which string is firstName and which is lastName so here comes the @Named annotation for...
Read more >NoSuchElementException - Android Developers
Constructs a NoSuchElementException , saving a reference to the error message string s for later retrieval by the getMessage method.
Read more >NoSuchElementException (Java Platform SE 8 )
Class NoSuchElementException · Constructor Summary · Method Summary · Methods inherited from class java.lang.Throwable · Methods inherited from class java.lang.
Read more >Dagger
Dagger is a fully static, compile-time dependency injection framework for both Java and Android. It is developed by the Java Core Libraries Team...
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
@0legg @tasomaniac you’ll be happy to know we are indeed currently working on fixing these types of issues so that you get a proper error message.
Part of the fix is improving the error messages for superficial validation (#2208), and the other part is making sure we have sufficient superficial validation for all types before we use them.
This particular issue is due to a lack of superficial validation before using a Module. Stacktraces like in https://github.com/google/dagger/issues/1793#issuecomment-705224100 are super helpful for us to pinpoint where we are missing this validation, but sometimes even with the stacktrace it’s difficult to determine exactly how we got in that state. Thus, even better would be if you could provide a sample project that reproduces the issue, or debug in AndroidStudio/Intellij using the instructions in https://github.com/google/dagger/issues/3090#issuecomment-987593534 to give us more information about the setup that causes this failure. Once we know exactly how we got in this state, we can write a regression test and fix the issue.
I’ve faced the same kind of error as @vRallev (well, in the same codebase) when moving classes from one Gradle module to another. The only change in code structure was making some dependencies of a module
implementation
rather thanapi
, so some parent components are not visible anymore. Anyway, one way or another, it’s impossible to pinpoint what was the root cause, as even with--stacktrace
there are 0 references to our code, only annotation processor, dagger and java internals.