【日常踩坑】ButterKnife:Attribute value must be constant
Attribute value must be constant
在搜索Attribute value must be constant后得到这样的说明:
Injection does not work in library projects
意为:在AndroidStudio的library的module中无法使用ButterKnife。
--------2017年8月23日更新--------
经提醒,ButterKnife在8.1.0后期及之后版本中已经对【在library的module中使用butterknife】提供了支持:
图片截于2017/08/23。这是。
通过gradle插件的形式可以使得butterknife在library的module中使用。
所以在library的module中使用butterknife的操作步骤如下:
-
1 在project的build.gradle中的buildscript节点的repositories节点下添加mavenCentral();在buildscript节点的dependencies节点下添加classpath com.jakewharton:butterknife-gradle-plugin:x.x.x(使用对应的版本号) 2 在library的module的build.gradle的文件开头添加apply plugin: com.jakewharton.butterknife;在dependcies节点下添加
compile com.jakewharton:butterknife:8.8.1 annotationProcessor com.jakewharton:butterknife-compiler:8.8.1
亲测后发现,哪怕在butterknife8.1.0后期及其之后的版本中不添加此插件,仍然会报这个错。这时候你就应该好好检查一下是否依赖了该gradle插件。为确保添加依赖无误,还是遵循butterkinfe的官方文档为好。