辩论中的android中butterknifee

1383人阅读
Android中上层源码分析与基本实践(22)
今天在看一个Android中的开源项目,发现用到了butterknife框架,在实际运行过程中总是报空指针的错误,由此问度娘,忽略了一个细节。大家注意一下,在官网上有一行小的英文提示:
Lastly, under &Java Compiler&, make sure that the Compiler compliance level is set to Java version 1.6 at minimum.
也就是说确保Jdk编译的时候最低版本是1.6,由此最终解决。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:24522次
排名:千里之外
原创:28篇
(1)(1)(6)(2)(1)(3)(5)(6)(1)(6)butterknife在library中使用问题处理
1. 官方指南及遇到的问题butterknife当前版本是8.4.0,已经提供了对library project的支持,github主页的使用步骤总结一下就是:1.To use Butter Knife in a library, add the plugin to your buildscript:buildscript&{
&&repositories&{
&&&&mavenCentral()
&&dependencies&{
&&&&classpath&'com.jakewharton:butterknife-gradle-plugin:8.4.0'
}2.and then apply it in your module:apply&plugin:&'com.android.library'
apply&plugin:&'com.jakewharton.butterknife'
dependencies&{
&&compile&'com.jakewharton:butterknife:8.4.0'
&&annotationProcessor&'com.jakewharton:butterknife-compiler:8.4.0'
}3.Now make sure you use R2 instead of R inside all Butter Knife annotations.class&ExampleActivity&extends&Activity&{
&&@BindView(R2.id.user)&EditText&
&&@BindView(R2.id.pass)&EditText&
}但是按照这个步骤操作后并没有效果,用@BindView的地方提示NullPointerException,用@onClick的标注的点击事件,点击后也没有反应2. 最终解决方案最后发现,只需修改一下上述步骤1和2就可以了。步骤1加上依赖注入的plugin:buildscript&{
&&&&repositories&{
&&&&&&&&jcenter()
&&&&&&&&mavenCentral()
&&&&dependencies&{
&&&&&&&&classpath&'com.neenbedankt.gradle.plugins:android-apt:1.8'&//&添加的部分
&&&&&&&&classpath&'com.jakewharton:butterknife-gradle-plugin:8.4.0'
}然后步骤2也修改一下:apply&plugin:&'com.android.library'
apply&plugin:&'com.jakewharton.butterknife'
apply&plugin:&'android-apt'
dependencies&{
&&compile&'com.jakewharton:butterknife:8.4.0'
&&apt&'com.jakewharton:butterknife-compiler:8.4.0'&//&修改的地方&把annotationProcessor改为apt
}这样处理之后,就正常了!而且我们可以看到,在路径下,已经生成了对应的中间文件:&顶0作者:
评论内容:

我要回帖

更多关于 butterknife 8.5.1 的文章

 

随机推荐