解决ButterKnife在library中报“Attribute value must be constant”

2019-04-09 17:06:15

Android开发,在library中使用ButterKnife,需要做一些配置否则会遇到一些问题。
我开发中遇到的问题是,通过@BindView(R.id.xxx)查找控件时,会报“Attribute value must be constant”的异常。
解决方案如下:

  1. 在根目录build.gradle文件的dependencies目录下添加如下:
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'

  2. 在module的build.gradle文件的顶部加入apply plugin: 'com.jakewharton.butterknife'

  3. 在module的build.gradle文件的dependencies目录下添加如下:
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

  4. 在module中使用R2代替R来findViewById即可.
    @BindView(R2.id.xxx)




  • 2021-01-16 09:45:19

    tabbar的titlePositionAdjustment设置文字距离

    指定相应的数据去偏移一个位置,向右或者向下为正值,向左或者向上为负值,不过首先你得有一个相对位置的坐标。而tabbarItem文字的坐标是底部为x轴,y轴则是tabbarItem的centerX;

  • 2021-01-16 09:49:13

    Cocoapods如何查看项目中引入库的版本号

    项目中已经安装过Cocoapods,并生成了Podfile.lock文件。 打开终端,cd命令切换到项目中的Podfile.lock文件目录下,执行命令:cat Podfile.lock 即可。也可以用文本方式打开 Podfile.lock 文件。示例如下:

  • 2021-01-18 13:50:21

    vue实现粘贴功能

    paste事件就是粘贴事件 需要通过clipboardData获得粘贴的内容

  • 2021-01-18 15:12:57

    flex和inline-flex区别

    flex: 将对象作为弹性伸缩盒显示 inline-flex:将对象作为内联块级弹性伸缩盒显示