square / mortar

A simple library that makes it easy to pair thin views with dedicated controllers, isolated from most of the vagaries of the Activity life cycle.
Apache License 2.0
2.16k stars 156 forks source link

ClassNotFoundException in dagger2support/DaggerService #138

Closed seligijus closed 9 years ago

seligijus commented 9 years ago

Hey,

After Google/Dagger 2.0 release, I get ClassNotFoundException in this line: Class<?> generatedClass = Class.forName(generatedName);

Generated classes are now called DaggerMyCustomComponent instead of DaggerMyCustomComponent, so the problem is in this line: String generatedName = (packageName + ".Dagger" + simpleName).replace('$', '_');

I solved this problem by removing ' ' symbol after .Dagger String generatedName = (packageName + ".Dagger" + simpleName).replace('$', '');

alex-townsend commented 9 years ago

In the meantime it still possible to just create the DaggerComponent using the builder supplied through the Dagger 2.0 generated classes, instead of using mortar's DaggerService.createComponent method. You can then register the created component with the DaggerService and the mortar scope and the component will then be returned with DaggerService.getDaggerComponent.

At least that's how I've been doing it. It should avoid the reflection used in DaggerService's createComponent as well.