欢迎使用CSDN-markdown编辑器

来源:互联网 发布:js json 遍历 编辑:程序博客网 时间:2024/06/06 16:52

集成android-apt,报警告解决方法

Android Studio2.3版本,集成dagger,butterknife,使用以前的依赖方式android-apt,如下

这里写图片描述

会报警告

Warning:Using incompatible plugins for the annotation processing: android-apt.This may result in an unexpected behavior.

然后编译运行也会有警告和报类找不到异常
Information:Gradle tasks [:app:assembleDebug]
Warning:Using incompatible plugins for the annotation processing: android-apt. This may result in an unexpected behavior.
D:\Android\ASWork\trunk\Hanfuhui\app\src\main\java\com\hanfuhui\entries\Album.java
Error:(6, 52) 错误: 找不到符号
符号: 类 BR
位置: 程序包 com.android.databinding.library.baseAdapters
D:\Android\ASWork\trunk\Hanfuhui\app\src\main\java\com\hanfuhui\albums\AlbumActivity.java
Error:(8, 32) 错误: 程序包com.hanfuhui.databinding不存在
Error:(19, 13) 错误: 找不到符号
符号: 类 ActivityAlbumBinding
位置: 类 AlbumActivity
D:\Android\ASWork\trunk\Hanfuhui\app\src\main\java\com\hanfuhui\handlers\AlbumHandler.java
Error:(9, 20) 错误: 找不到符号
符号: 类 BR
位置: 程序包 com.hanfuhui
D:\Android\ASWork\trunk\Hanfuhui\app\src\main\java\com\hanfuhui\albums\AlbumFragment.java
Error:(19, 20) 错误: 找不到符号
符号: 类 BR
位置: 程序包 com.hanfuhui
Error:(26, 32) 错误: 程序包com.hanfuhui.databinding不存在
Error:(64, 13) 错误: 找不到符号
符号: 类 ItemSingleLineTopBinding
位置: 类 AlbumFragment

解决方法:
直接删除classpath’com.neenbedankt.gradle.plugins:android-apt:1.8’和applyplugin:’android-apt’,然后将apt替换为annotationProcessor

buildscript {
repositories {
jcenter()

}dependencies {    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'}

}

apply plugin: ‘android-apt’

修改引用为:
修改前
apt “com.google.dagger:dagger-compiler:2.6”
修改后
annotationProcessor “com.google.dagger:dagger-compiler:2.6”

重新同步build,警告没了。但在运行编译时会报其它警告,如下

Information:Gradle tasks [:app:assembleDebug]
D:\Android\ASWork\trunk\Hanfuhui\app\src\main\java\com\hanfuhui\utils\FrescoUtils.java
Error:(141, 24) 警告: Application namespace for attribute app:banner will be ignored.
Error:(154, 24) 警告: Application namespace for attribute app:avatar will be ignored.
Error:(198, 24) 警告: Application namespace for attribute app:fresco will be ignored.
Warning:warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.alipay.android.phone.mrpc.core.c) that doesn’t come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any “-target” type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is not an inner class.

建议直接Github上依赖最新版本.

android-apt报警告是该作者在官网发表声明证实了后续将不会继续维护android-apt,

Google官方 插件提供了名为annotationProcessor的功能来完全代替android-apt