Android: Why do we need to use R2 instead of R wit

2020-04-03 03:16发布

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.

1条回答
Animai°情兽
2楼-- · 2020-04-03 03:41

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

查看更多
登录 后发表回答