ButterKnife 组件化相关配置

一:官方给butterKnife的模块化使用方式和我的组件化项目结构


二:组件化中ButterKnife使用
1.在工程project的build.gradle下添加butterKnife插件依赖

classpath "com.android.tools.build:gradle:3.5.4"classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.0'//butterKnife组件化第一步

注:这有一个Gradle和ButterKnife版本编译冲突问题
2.在common_base库公共依赖库build.gradle中添加

//ButterKnife第三步功能基础组件中依赖api rootProject.ext.dependencies["butterknife"]//等价于:api 'com.jakewharton:butterknife:10.2.0'//annotationProcessor rootProject.ext.dependencies["butterknifeCompiler"]//这个每个用到butterKnife都需要添加故基础组件可以不添加

使用api是为了其他依赖这个库都能使用,不用重复添加,具体可以看看api,implementation ,compile区别
3.App壳模块中添加,是application模块

apply plugin: 'com.android.application'implementation project(path: ':common_base')//黄油刀ButterKnife//这个东西一定要放在这个里面,否则会报错的(空指针)!annotationProcessor rootProject.ext.dependencies["butterknifeCompiler"]//等价于:annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'

4.在其他lib库模块需要添加

apply plugin: 'com.android.library'apply plugin: 'com.jakewharton.butterknife'//相应的库module模块添加这个implementation project(path: ':common_base')//黄油刀ButterKnifeannotationProcessor rootProject.ext.dependencies["butterknifeCompiler"]//等价于:annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'

三:ButterKnife使用相关问题
1.Gradle和ButterKnife版本冲突相关问题,具体不知,一般是降低Gradle版本
2.butterknife报空指针问题 需要添加annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
3.在其它Module中使用Butterknfie怎么使用(主要是解决R资源的问题)

@BindView(R2.id.login_tv)//通过R2TextView login_tv;ButterKnife.bind(this);

原因:当作为库的一部分构建时,R.java生成的类中的值不会被声明为“final”.用于@BindView()的注释需要这些R.值是最终的,以后不会更改.
故:ButterKnife就使用了一个插件,拷贝R中所有的值到R2中,并且把R2中的值都设置成了final类型的,这样就能蒙混过关,反正子模块中的值可能还是要重新设置的。

更多相关文章

  1. Android(安卓)View添加Listener小技巧
  2. Lifecycle-Aware Components生命周期组件 Lifecycle、LiveData
  3. Android(安卓)sdk更新过程中出现问题 (连接不上Google的服务资源
  4. Android(安卓)4.4.2 禁用通知栏下拉
  5. linux程序崩溃调试技术
  6. 漫谈android系统(1)解析android编译
  7. android 平台USB wifi驱动移植及使用
  8. RecyclerView 入门教程(超详细)
  9. Android开发,在Activity启动时,默认隐藏软键盘。和遮挡Edittext时

随机推荐

  1. android sqlite 操作
  2. Android开发秘籍学习笔记(一)
  3. Android学习日记-------SQLite数据库操作
  4. Android(安卓)SDK中tools详解
  5. Android一级目录介绍
  6. android:windowSoftInputMode属性的使用
  7. Android(安卓)iptables 今天小结
  8. 【Android】基于XMAPP协议实现Android推
  9. Eclipse环境下格式化Android的代码风格
  10. Android(安卓)方向传感器 (Orientation Se