Strange instantiation problems with RG3 - Could not find a suitable constructor for class

155 views
Skip to first unread message

Pawel Tschudnowsky

unread,
Nov 6, 2014, 11:45:09 AM11/6/14
to robo...@googlegroups.com
Hi,

I understand that I must be missing something due to some changes in guice 4 and/or rg3.
I have some classes that I instantiate directly with getInjector(context).getInstance which have one constructor with context parameter,
properly annotated with @Inject - they worked just fine in RG2

for instance
    @Inject
    public MaintenanceSyncAdapter(Context context)
    {
        super(context);
    }

and still I get an exception "Could not find a suitable constructor for class, Classes must have either one (and only one) constructor bla-bla-bla".
What do I do wrong? I do not use blender and I've read the upgrade guide finding nothing helpful.


Thanks for your help in advance.

Craig McIlwee

unread,
Nov 6, 2014, 11:55:37 AM11/6/14
to robo...@googlegroups.com
It sounds like you have annotation database support enabled (the default) but don't have roboblender setup.  You should either check the the RG2 -> RG3 upgrade guide for the steps to get roboblender going or disable annotation databases, but beware that disabling annotation databases may have it's own issues (at least in my experience, see my post here).

Craig

Pawel Tschudnowsky

unread,
Nov 6, 2014, 12:00:36 PM11/6/14
to robo...@googlegroups.com


It sounds like you have annotation database support enabled (the default) but don't have roboblender setup.

in this case I would get the "AndroidDatabaseImpl not found" exception. No, I disabled annotation databases with the call RoboGuice.setUseAnnotationDatabases(false) in Application.onCreate

Craig McIlwee

unread,
Nov 6, 2014, 12:03:13 PM11/6/14
to robo...@googlegroups.com
"AndroidDatabaseImpl not found" sounds like a misconfiguration.  I think this is something you probably want to work out because it will benefit your app's performance, in my case I only tried to disable it for development builds.

Pawel Tschudnowsky

unread,
Nov 6, 2014, 12:12:47 PM11/6/14
to robo...@googlegroups.com

"AndroidDatabaseImpl not found" sounds like a misconfiguration.

well, this is what you get if you didn't disable annotations
 
 I think this is something you probably want to work out because it will benefit your app's performance

I know, but damn - I didn't want to use rg3 at all at this stage. I came across a bug with rg2 when fragments are not injected with tag properly.
And since there was no version released with bugfix for this I thought - maybe I try rg3 instead of creating my own version of rg2

Craig McIlwee

unread,
Nov 7, 2014, 9:52:12 AM11/7/14
to robo...@googlegroups.com


On Thursday, November 6, 2014 12:12:47 PM UTC-5, Pawel Tschudnowsky wrote:

"AndroidDatabaseImpl not found" sounds like a misconfiguration.

well, this is what you get if you didn't disable annotations
 

You never said whether you followed the roboblender guide before giving up on the annotation database.  If you did and you are still getting the "AndroidDatabaseImpl not found" then you probably have done something wrong on your side.  Post some configurations (gradle, android manifest) here and we can take a look.

Pawel Tschudnowsky

unread,
Nov 7, 2014, 12:14:48 PM11/7/14
to robo...@googlegroups.com


You never said whether you followed the roboblender guide before giving up on the annotation database.  If you did and you are still getting the "AndroidDatabaseImpl not found"

Craig, I don't need annotation database and all the blender stuff right now. I just want the 3.0 version to work old-style because as I explained before - I either have to maintain my own 2.0 version with bugs fixed (which I ultimately had to do) or take 3.0 where they were also fixed and make it work without having to solve all the problems introduced with blender. I just don't have time for this right now. So again -  I turned annotation database off, I didn't include roboblender as maven dependency and I still get the exception with wrong constructor. As soon as I switch to 2.0 the sun shines again.
 

Craig McIlwee

unread,
Nov 7, 2014, 1:58:36 PM11/7/14
to robo...@googlegroups.com
Ok, fair enough.  It seems like you are running into the same issues that I posted about a week or so ago.  There hasn't been any response yet, and I guess I'm not the only one running into it, so I'm gonna spend some time trying to track it down.  At this point it looks like there may be an issue with the way RoboGuiceHierarchyTraversalFilter is being used.  If I figure anything out I'll post here and in the other thread.

Craig McIlwee

unread,
Nov 7, 2014, 3:10:46 PM11/7/14
to robo...@googlegroups.com
Pawel, are you using targeted bindings that require injection?  In other words, bind(Interface.class).to(Implementation.class) where Implementation requires injection?  So far I've found that those cause issues where @ImplementedBy(Implementation.class) works fine.  I'm also seeing problems when binding to a provider that requires injection.

Craig

Pawel Tschudnowsky

unread,
Nov 7, 2014, 3:25:26 PM11/7/14
to robo...@googlegroups.com

I have pretty large project, so I use a lot of different injections - and yes, plenty of  bind(Interface.class).to(Implementation.class) . But those that fail on startup (who knows which would also fail if not them) are not bound in configuration module. They are injected by implementation - with getInstance(Implementation.class), they don't implement any interface (but have a common super class if that matters)

Craig McIlwee

unread,
Nov 7, 2014, 4:02:42 PM11/7/14
to robo...@googlegroups.com
Yeah, it isn't just the targeted bindings.  Those were just the ones that showed up first.  Once I fixed the first set of errors I ran into a bunch more for classes that weren't mentioned in any modules.  By 'fixed' I mean that I switched them over to member injection, which is a pretty crappy workaround.  So it looks like constructor injection isn't fully supported by RoboGuice, I guess they only considered the subclasses of Android classes that require member injection in onCreate and didn't put much effort into other classes that use constructor injection.  Anyways, I filed an issue here.

Pawel Tschudnowsky

unread,
Nov 8, 2014, 6:12:27 AM11/8/14
to robo...@googlegroups.com
thanks for your diligence. rb3 doesn't look ready for prime time just yet. So you say, those problems do not exist if annotation database is used? I will give it a try when I have time. 

Craig McIlwee

unread,
Nov 8, 2014, 9:04:14 AM11/8/14
to robo...@googlegroups.com
Yeah, everything works perfectly with the annotation database.  It really doesn't take much time to set up, most of my time was spent getting the correct dependencies on the annotation processing classpath in eclipse since I haven't made the switch to android studio yet, but I can provide the required config if anyone needs it.

Mike Burton

unread,
Nov 8, 2014, 10:22:07 AM11/8/14
to robo...@googlegroups.com, robo...@googlegroups.com
Great sleuthing, thank you Craig. Most of our testing has been with the annotationdatabase on since that's the main value of rg3.  We'll look into who it doesn't work with the db off

sent from a magical device that lives in my pocket. Please excuse brevity


--
You received this message because you are subscribed to the Google Groups "roboguice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roboguice+...@googlegroups.com.
To post to this group, send email to robo...@googlegroups.com.
Visit this group at http://groups.google.com/group/roboguice.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages