ButterKnife项目地址:https://github.com/JakeWharton/butterknife

AndroidX按照正常的方式集成:

android {  ...  // Butterknife requires Java 8.  compileOptions {    sourceCompatibility JavaVersion.VERSION_1_8    targetCompatibility JavaVersion.VERSION_1_8  }}dependencies {  implementation 'com.jakewharton:butterknife:10.1.0'  annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'}
buildscript {  repositories {    mavenCentral()    google()   }  dependencies {    classpath 'com.jakewharton:butterknife-gradle-plugin:10.1.0'  }}

集成完成以后,自动生成的BindView中的View 是Null,多方查找未果,结果在一个老的项目中找到了答案,于此记录一下;

这个是我的项目结构,我把常用的一些工具类和常用的第三方放在了common模块中(ButterKnife也在这个模块中);

但是我在主模块app中使用ButterKnife生成的控件一直是Null

etPhone、etPwd均是Null;

解决方法是在app模块的gradle中增加注解annotationProcessor(注解处理器)

annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

也就是说,我在common模块中引入了ButterKnife,如果在app模块中使用的话,还要在app模块加入annotationProcessor,不然app模块没有办法根据注解生成Java或R文件;

如果加了这个还是null或报错,可以加上  apply plugin: 'com.jakewharton.butterknife' 试试;

总结,使用ButterKnife的模块必须有注解处理器 annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

类似使用到注解处理器的框架还有很多 ButterKnife、Glide 、Arouter、Dagger2等等。。。

 

更多相关文章

  1. android studio 上junit4的使用
  2. Android(安卓)SDK开发 -- TitleBar重构 (代理模式的使用)
  3. Android使用了ProGuard时注意的事项
  4. android 通知Notification的使用小实例(振动,灯光,声音)
  5. Android中Activity多页滑动切换效果(使用ViewFlipper)
  6. Android(安卓)使用Android(安卓)Studio + Gradle 或 命令行 进行
  7. Android(安卓)Studio 使用github
  8. Android(安卓)Library Project 使用问题总结
  9. android技术开发例子,解析以及源码集锦

随机推荐

  1. android studio2.0遇到的问题及解决方案
  2. 学习Android闹钟源代码(三)-AlarmClock类
  3. Android中文API(125) —— VideoView
  4. android 常见死机问题-如何分析
  5. Android(安卓)初体验
  6. android所有需要的Demo地址
  7. 【Android基础】Activity的启动模式(andr
  8. 解决Intellij idea运行android applicati
  9. Android游戏引擎《Rokon》学习笔记六:一个
  10. Android(安卓)网络框架初探