JessYanCoding / MVPArms

⚔️ A common architecture for Android applications developing based on MVP, integrates many open source projects, to make your developing quicker and easier (一个整合了大量主流开源项目高度可配置化的 Android MVP 快速集成框架).
Apache License 2.0
10.29k stars 2.39k forks source link

又有新问题,ButterKnife 和 Dagger2 冲突,导致空指针 #14

Closed jp1017 closed 7 years ago

jp1017 commented 7 years ago

请问您遇到过吗?我测试了一上午了,,

只有一个TextView

@BindView(R.id.tv_hello)
Textview mTextView;

然后在 initData() 方法里设置内容 mTextView.setText("你好");`

就报 mTextView 空指针了,不用黄油刀,findViewbyId 正常。

也有说两者冲突,https://github.com/JakeWharton/butterknife/issues/803

然而并。。没解决。。。

我的工程和你的项目对比了,都一样,,我的不行,你的完美运行,好尴尬,,,求破啊

JessYanCoding commented 7 years ago

在baseActvivity的oncreate方法中,ButterKnife.bind(this);应该在initData方法前执行

jp1017 commented 7 years ago

是啊,initData就在他后面

        ......

        mUnbinder = ButterKnife.bind(this);
        ComponentInject();//依赖注入
        initData();
JessYanCoding commented 7 years ago

建议你按两下shift,看下有没有 (acivity名)$$ViewBinder.java 这个类,看下里面找到id没,这框架我们公司几个项目都在用,一直没出现过你说的问题

jp1017 commented 7 years ago

@JessYanCoding 刚看了下,build下确实没有黄油刀产生的东西,,只有dagger2产生的。。真是冲突了吗?

jp1017 commented 7 years ago

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

按照上面的文章修改后,build下有黄油刀生成的资源了,还是空指针。。。还会哪里不对呢

jp1017 commented 7 years ago

@JessYanCoding 解决了,就是上面的解决方案 :smile:

pangff commented 7 years ago

@jp1017 那个文章并没有说butterknife怎么配置的啊

jp1017 commented 7 years ago

@pangff 官网有,和上面的一样 使用annotationProcessor, 官网,看官网,没错!

pangff commented 7 years ago

@jp1017 我两都用的annotationProcessor,但是编译会出错 annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0' annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

jp1017 commented 7 years ago

annotationProcessor 要AS 2.2+

pangff commented 7 years ago

@jp1017 classpath 'com.android.tools.build:gradle:2.2.2' compile 'com.google.dagger:dagger:2.2' annotationProcessor 'com.google.dagger:dagger-compiler:2.2' compile 'com.jakewharton:butterknife:8.4.0' annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'

和引号没有关系,这样还是不行

jp1017 commented 7 years ago

具体报啥错呢,,,

JessYanCoding commented 7 years ago

compile 'com.google.dagger:dagger:2.2' apt 'com.google.dagger:dagger-compiler:2.2' compile 'com.jakewharton:butterknife:8.4.0' apt 'com.jakewharton:butterknife-compiler:8.4.0'

jp1017 commented 7 years ago

嗯,butterknife在library和app配置有些不一样,具体看他官网

pangff commented 7 years ago

@jp1017 换了dagger版本到2.8可以了。非常感谢

knightzc commented 6 years ago

我也有这个问题,测试好久了还没解决,跟demo里的配置来的,demo就没问题,我的就有问题,不知道咋回事

knightzc commented 6 years ago

@jp1017 请问你是怎么解决的,我看了下我有生成viewbinding,里面也有id,但还是不行

JessYanCoding commented 6 years ago

@knightzc https://github.com/JessYanCoding/MVPArms/wiki/Issues#7