如何解决Databinding和Dagger冲突

来源:互联网 发布:java重写hashcode方法 编辑:程序博客网 时间:2024/06/13 00:00

转载请注明出处:http://blog.csdn.net/qq_31679853/article/details/78672853

1.在使用DataBinding,Android studio出现警告:


Warning:Using incompatible plugins for the annotation processing: android-apt. This may result in an unexpected behavior.
Error:(6, 53) 错误: 程序包com.example.liuguirong.lgrandroid.databinding不存在
/Users/liuguirong/Downloads/LgrAndroid/app/src/main/java/com/example/liuguirong/lgrandroid/MainActivity.java
Error:(13, 62) 错误: 找不到符号
符号: 类 ActivityMainBinding
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

警告的翻译:警告:使用不兼容的插件进行注释处理:android-apt。 这可能会导致意外的行为。

在解决这个冲突前 我们需要明白: android-apt 和 annotationProcessor

(1)android-apt是由一位开发者自己开发的apt框架,源代码托管在这里,随着Android Gradle 插件 2.2 版本的发布,Android Gradle 插件提供了名为 annotationProcessor 的功能来完全代替 android-apt ,自此android-apt 作者在官网发表声明最新的Android Gradle插件现在已经支持annotationProcessor,并警告和或阻止android-apt ,并推荐大家使用 Android 官方插件annotationProcessor。

(2)annotationProcessor是APT工具中的一种,他是google开发的内置框架,不需要引入,可以直接在build.gradle文件中使用;

2.如何解决 :

android-apt切换为annotationProcessor

1.删除(注意Android的编译版本一定要在2.2(含)以上,我的编译版本是2.3.3
 
2修改dagger依赖伟annotationProcessor 
3.最后clean project 
注意:butterknife,也可以通过annotationprcessor替代apt

[html] view plain copy
  1. annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'  
  2.    compile 'com.jakewharton:butterknife:8.4.0'  


原创粉丝点击