运行环境
win7_64
studio3.1.2
Butterknife8.8.1
当在module中使用butterknife时,会提示Attribute value must be constant,如下图1-2所示:

解决方法:
1).在根目录下的build.gradle中的dependencies添加如下:
这里注意是8.4.0的版本!!
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.4.0'
}
}
2).在你module中的build.gradle顶部t添加如下代码:
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
3).最后,在module中的build.gradle 中的dependencies中添加:
dependencies {
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
4)然后在module中使用R2代替R来findViewById即可,如下图1-3所示:

以上就是解决如何在在library中使用butterknife
网友评论