原文地址:https://www.jianshu.com/p/b0999774fd15
使用了ButterKnife8.8.1后出现空指针的问题,但也有些人说没问题。我看了这两个人的配置,基本都是按照JakeWharton大神在github上面说明进行配置的;但为什么一个是正常的,而一个却出现空指针?
build {
repositories {
mavenCentral()
}
dependencies {
classpath \'com.jakewharton:butterknife-gradle-plugin:8.8.1\'
...
}
}
apply plugin: \'com.jakewharton.butterknife\'
apply plugin: \'com.android.library\'
apply plugin: \'com.jakewharton.butterknife\'
dependencies {
...
compile \'com.jakewharton:butterknife:8.8.1\'
annotationProcessor \'com.jakewharton:butterknife-compiler:8.8.1\'
}
经过仔细对比了一下
发现出错的一方是因为在library module里面进行如下引用
compile \'com.jakewharton:butterknife:8.8.1\'
annotationProcessor \'com.jakewharton:butterknife-compiler:8.8.1\'
而未出错的一方是因为在app module里面进行如下引用
compile \'com.jakewharton:butterknife:8.8.1\'
annotationProcessor \'com.jakewharton:butterknife-compiler:8.8.1\'
有些项目可能由几个依赖的library module和app module组成,所以由于依赖关系,
compile \'com.jakewharton:butterknife:8.8.1\'
butterknife的导入必须放在library module。
那么如何解决呢?解决方法很简单,在 app module 内引用 annotationProcessor
annotationProcessor \'com.jakewharton:butterknife-compiler:8.8.1\'
而在 library module内引用 butterknife 即可解决。
compile \'com.jakewharton:butterknife:8.8.1\'
作者:自由懒散的码农
链接:https://www.jianshu.com/p/b0999774fd15
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
继续阅读与本文标签相同的文章
可以获取随机图片的API收集
-
Apache Flink 进阶(一):Runtime 核心机制剖析
2026-05-18栏目: 教程
-
RocketMQ一个新的消费组初次启动时从何处开始消费呢?
2026-05-18栏目: 教程
-
Spring Boot2中整合atomikos来实现不同类型数据库的分布式事务一致性
2026-05-18栏目: 教程
-
Git 如何针对项目修改本地提交提交人的信息
2026-05-18栏目: 教程
-
工作几年只会增删改查怎么了,大神们都是从第一行代码开始的
2026-05-18栏目: 教程
