JakeWharton / butterknife

Bind Android views and callbacks to fields and methods.
http://jakewharton.github.io/butterknife/
Apache License 2.0
25.55k stars 4.6k forks source link

ButterKnife8.4.0 and Dagger2 plugin conflict #803

Closed Khaos116 closed 7 years ago

Khaos116 commented 8 years ago

Because dagger2 need use apply plugin: 'com.neenbedankt.android-apt',so butterknife8.4.0 is always NullPointException

Khaos116 commented 8 years ago

经测试,使用com.neenbedankt.android-apt这个插件必然导致 butterknife8.4.0空指针; 可以使用低版本的butterknife避免这个问题,但是如果使用了dagger2.2可能会出现编译问题(改为dagger2.0.2即可)

manjunathc23 commented 8 years ago

+1

vzeitler commented 8 years ago

do you have "apt 'com.jakewharton:butterknife-compiler:8.4.0'" in your dependencies ?

J1aDong commented 8 years ago

@vzeitler @caiyoufei +1,经测试,在引用android-apt的情况下,将com.jakewharton:butterknife-compiler:8.4.0的annotationProcessor前缀改为apt可以正常工作

jp1017 commented 8 years ago

@caiyoufei see thie blog:

http://www.jianshu.com/p/268c14130bea

We all see, the two libs recommand using annotationProcessor

caoyanglee commented 7 years ago

dependencies { compile 'com.jakewharton:butterknife:8.4.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' }

use apt replace of annotationProcessor! use apt replace of annotationProcessor! use apt replace of annotationProcessor!

ceduliocezar commented 7 years ago

Replacing annotationProcessor for apt as @CaoyangLee mentioned worked for my project.

Emeritus-DarranKelinske commented 7 years ago

This is how I got both to work together:

// Butter Knife
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'
// Dagger 2
apt 'com.google.dagger:dagger-compiler:2.8'
compile 'com.google.dagger:dagger:2.8'
provided 'javax.annotation:jsr250-api:1.0'
Davids89 commented 7 years ago

Thanks @Emeritus-DarranKelinske

renhuihhh commented 7 years ago

@caiyoufei dagger2 都2.8了 我用的2.8没发现有这个问题哦

TonyTangAndroid commented 7 years ago

@renhuihhh 参考 Emeritus-DarranKelinske 给出的答案

hoombar commented 7 years ago

The option that @Emeritus-DarranKelinske provided doesn't seem to work when you are using ButterKnife inside a library by applying the plugin

apply plugin: 'com.jakewharton.butterknife'

My best guess would be because of the reference to the support annotation processor in the plugin instead of referencing APT, is this likely?

public final class FinalRClassBuilder {
  private static final String SUPPORT_ANNOTATION_PACKAGE = "android.support.annotation";

My thoughts on this are that no action is needed as Dagger 2 should be playing nicely with annotationProcessor instead of relying on apt (deprecated as of Gradle Android plugin 2.2).