-
想实现的效果:
代码中为了实现业务逻辑的解耦,经常使用多module进行业务逻辑处理。这就需要有一个common的库,对各类通用的弹框,组件等进行处理。
-
遇到的问题:
在common库中使用ButterKnife绑定控件一直报错 “Attribute value must be constant”
-
问题原因:
library module中的R中id未用final修饰
-
解决方案,在Lib中使用 R2绑定控件
-
具体操作方法:
在 Library projects 中
buildscript {
repositories {
mavenCentral() // 添加
}
dependencies {
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1' // 添加
}
}
在Lib module中
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife' // 添加
在具体绑定文件中:
class ExampleActivity extends Activity {
@BindView(R2.id.user) EditText username; // 修改 R 为 R2
@BindView(R2.id.pass) EditText password; // 修改 R 为 R2
...
}