-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Dagger unable to inject generated classes #410
Comments
Dagger issue is being tracked here: square/dagger#410
The problem is that Dagger requires that classes that has Since you are using AndroidAnnotations it looks that you cannot inject generated classes directly, you might create some proxy class that could be injected and responsible for creating AndroidAnnotations objects. BTW why Dagger even requires those empty annotations for constructor? |
The short answer to why Dagger requires @Inject constructors is seen in
If permitted non-@Inject-annotated constructors, then we then use Foo, We saw a lot of those sorts of errors in Guice, where unintended I'll answer the SO question on SO. |
I totally understand why Dagger needs the Module:
MainActivity.java
DaggerAAExample.java
I've included the relevant code. Now, the trick is, Android Annotations at compile-time generates the AAPrefs_.java file. Dagger appears to find it, and the ObjectGraph appears to build successfully at compile. However, at runtime, I get the error as shown above. This is all doing a debug build, so I can't imagine that Proguard is messing anything up. I'm making sure to use an All I need to do for the example to work is just copy the file Android Annotations created to the src/ folder, rename it, rename the injections, and everything works. No code changes beyond the class name. That's why I'm confused. I apologize if we seem to be talking past each other, please let me know if there's anything else I can do to clarify the issue. |
Yeah - so that code seems like it should work. Why it would be trying to implicitly-bind something that has a provides method is very odd. I'll try to play with the example project. |
We see this internally on scary classes that you'd never want Dagger to
|
It's not though, @JakeWharton. It seems like he's calling the constructor explicitly in an |
To Dagger it's the same thing. In our impl we pass the Application instance
|
Correct me if I'm wrong then, but this is a legitimate issue, I'm not just using Dagger the wrong way? |
I'm having the same issue. |
Bumped into the same issues with a difference the Dagger-generated classes don't see AA generated classes despite those all are successfully generated. Not to make confs overcomplicated thinking about getting rid AA. |
I'm sorry - I'm not following - what do you mean "AA" generated classes? On 4 September 2014 13:39, Eugene Beletskiy notifications@github.com
|
Meaning the classes generated by Android Annotations https://github.com/excilys/androidannotations |
Yeah - your issue is quite different than the issue described in this bug. On 5 September 2014 01:49, Eugene Beletskiy notifications@github.com
|
@JakeWharton @DjBushido I have a doubt about this code @module ( why we need to add injects {} in module or when or where we should use this annotation. |
It also seems to be the case that it gives this error when you provide the same object in multiple modules. |
Hello all!
I'm trying to get Dagger to inject some classes from the Android Annotations project. Normally, I wouldn't think this would be an issue, as theoretically Dagger can just inject the classes generated by Android Annotations.
However, as detailed in this SO question, that's not the case.
As a quick recap of the question, when trying to inject the generated class (using an
@Provides
in the module), Dagger fails at run-time with a message like the following:However, if I simply copy the class that would be injected into the main project, rename it (to avoid a name conflict), and point the module and Activity to the new class, then everything runs just fine.
Because of the second condition, I suspect this is an error with Dagger, and not with Android Annotations. That being said, I have no idea what would trigger this.
I have created a sample project to prove the issue is reproducible. You can find the project over here. Currently, the project will compile and run fine. But if you change the
@Inject
ed class toAAPrefs_
instead ofAAPrefsBuild
, and change theMainActivity
as well, you will receive the above error.Thank you, and let me know if there is anything else I can do to help.
The text was updated successfully, but these errors were encountered: