Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Why do we need to use R2 instead of R with butterknife?

I've been using butterknife for a few months and I've just noticed in its documentation that it says:

Now make sure you use R2 instead of R inside all Butter Knife annotations.

Why is that? I've been using R and everything works perfect.

like image 208
TheCrafter Avatar asked Feb 21 '17 08:02

TheCrafter


1 Answers

Using R2 is only necessary for building Android Library projects.

https://github.com/JakeWharton/butterknife#library-projects

It has to do with fact that the values in the R.java generated class aren't declared as "final" when built as part of a library. The annotations used for @BindView() need these R. values to be final and not subject to change later on.

I'm sure someone could explain all of this better -- but the bottom line is - you're just fine using "R." values in @BindView in an Android application

like image 65
jpage4500 Avatar answered Nov 12 '22 00:11

jpage4500