Android:为什么我们需要在黄油刀上使用R2而不是R? [英] Android: Why do we need to use R2 instead of R with butterknife?
问题描述
几个月来我一直在使用 butterknife ,我在其文档中注意到它说:
I've been using butterknife for a few months and I've just noticed in its documentation that it says:
现在,请确保在所有黄油刀中使用R2而不是R注释.
Now make sure you use R2 instead of R inside all Butter Knife annotations.
那是为什么?我一直在使用R,一切正常.
Why is that? I've been using R and everything works perfect.
推荐答案
只有在构建Android库项目时才需要使用R2.
Using R2 is only necessary for building Android Library projects.
https://github.com/JakeWharton/butterknife#library-projects
这与以下事实有关:当作为库的一部分构建时,R.java生成的类中的值未声明为最终".用于@BindView()的注释需要这些R.值是最终值,以后不得更改.
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.
我确定有人可以更好地解释所有这些内容-但最重要的是-使用"R"就可以了.Android应用程序中@BindView中的值
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
这篇关于Android:为什么我们需要在黄油刀上使用R2而不是R?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!