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

只愿长相守 提交于 2019-12-01 15:25:18

问题


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:


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



来源:https://stackoverflow.com/questions/42362062/android-why-do-we-need-to-use-r2-instead-of-r-with-butterknife

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!