5

I have a work and library projects. Dagger was used in the work project, and a few days ago I decide to use Dagger in the library project too. I configured Eclipse Java Compiler and Annotation Processing settings for the library project, added required Dagger & JavaWriter JARs, decalred a Module in the library project. Now both project doesn't have any error.

But when I attempting to run application on Android device, it crashes:

java.lang.RuntimeException:
Unable to create application com.iqm.smartapp.AlarmsApplication:
java.lang.IllegalStateException:
Module adapter for class com.iqm.library.IQMLibraryModule could not be loaded.
Please ensure that code generation was run for this module.

I think this caused because in the library project the .apt_generated folder is empty! Dagger isn't generates classes for the library project. Probably there is some IDE/project misconfiguration. But do exactly the came configuration in both work and library project and have no more idea, what can be wrong.

So my question: is it possible to use Dagger in Android library projects? And what should be the right Eclipse configuration to enable requires code generation?

Thanks in advance.

Edit: I made a new clean library project, set it for Dagger and copied all source files from the old one. At this moment all in the new project works as expected. Strange thing!

Vlad Kuts
  • 503
  • 5
  • 11

1 Answers1

0

I do not see any problems using Dagger inside a library. Your problem here is that it has not generated the necessary binding code.

To enable this inside Eclipse, see this link.

Sten Roger Sandvik
  • 2,526
  • 2
  • 19
  • 16
  • I'm verified at least 10 times the project properties, especially Java Compiler, Annotation Processing & Factory Path. They was right, but binding code didn't generated. In the new clean project all works as expected. I have no ideas what was broken in the old project. – Vlad Kuts Jan 21 '14 at 17:02
  • Remember to rebuild the project fully after changing the apt setting. – Thorbjørn Ravn Andersen Feb 04 '14 at 13:54
  • There seems to be an issue with dagger 2 (and I suspect the same is true for dagger 1.x) and library project when it comes to @Singletons and injecting them in the library project AND the concrete app project as described here: http://stackoverflow.com/q/31417795/1041533 – AgentKnopf Jul 16 '15 at 07:51