Why Butterknife doesn't work for Android Libraries

Have you tried using Butterknife library to bind Android's xml views for an Android library ? And ran into dreaded this error message:
Attribute must be constant

You're not alone ! Many people like myself tried using wonderful Butterknife in their Android Libraries like they do in their regular phone and tablet projects. Actually, Butterknife is not intended to be used for Android libraries project because R class in library project is not final. 

Here's the explanation from Jake himself:
Values on the R class are not final in library modules which makes this library unusable on those modules. This is a limitation of Java, and something this library has decided not to work around. See #2.
Recent version of Butterknife library (8.5.1)  supports library projects as well.  Checkout out this link to configure library projects to start using Butterknife in your library projects as well.

No comments:

Post a Comment

Scheduling Repeating Local Notifications using Alarm Manager

Learn about Scheduling Repeating Local Notifications using Alarm Manager in this post .