解决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)




  • 2017-07-26 11:57:00

    Laravel 定时任务

    在 php 中使用定时器是一件不太简单的事情,之前大概只能通过 cron 来实现定时任务。但是在 Laravel5 中,定时任务将会变得很简单。

  • 2017-08-03 21:16:46

    Node.js 里面那些遗失的 ES6 特性

    其实 Node.js 对 ES6 的很多特性都已经开始支持了。 在 Node.js 使用的 JS 引擎 V8 里面将不同状态 ES6 特性分成了 3 个等级:

  • 2017-08-08 11:17:17

    nginx 反向代理 取得真实IP和域名

    nginx反向代理后,在应用中取得的ip都是反向代理服务器的ip,取得的域名也是反向代理配置的url的域名,解决该问题,需要在nginx反向代理配置中添加一些配置信息,目的将客户端的真实ip和域名传递到应用程序中。