Search code examples
androidroboguice

Roboguice, ADT 14+, and Android library projects


Roboguice is such a neat little tool to tidy up boilerplate Android view code.

I loved using the @InjectView annotation so that I didn't have to initialize each and every view field in the onCreate() method of my Activities like this:

@InjectView(R.id.title) TextView title;

As part of Google's sweeping changes to library projects for ADT 14+ (which on the whole are a welcome improvement), id fields in generated R classes are no longer final.

So now when you want to use Roboguice inside of library projects, the @InjectView annotations no longer compile because annotations are processed at compile time, and R.id.title is no longer final.

Bummer...

Anybody else out there using Roboguice and have a creative workaround?


Solution

  • Android Annotations supports a resource name based injection with a compile-time check.

    https://github.com/excilys/androidannotations/wiki/Library-projects