原文地址:https://www.jianshu.com/p/b0999774fd15
使用了ButterKnife8.8.1后出现空指针的问题,但也有些人说没问题。我看了这两个人的配置,基本都是按照JakeWharton大神在github上面说明进行配置的;但为什么一个是正常的,而一个却出现空指针?
buildscript {
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
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
本文详细分析了使用ButterKnife8.8.1时出现空指针异常的原因,指出问题源于library module和app module中依赖配置的不同。通过对比正确的配置方式,提供了解决方案,即在app module中正确引用annotationProcessor,而在library module中仅引用ButterKnife。
2560

被折叠的 条评论
为什么被折叠?



