Android Studio 3.0注解处理器 [英] Android Studio 3.0 annotationProcessor

查看:153
本文介绍了Android Studio 3.0注解处理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试构建项目后出现以下错误:

I get the following error after I try to build my project:

Error:android-apt plugin is incompatible with the Android Gradle plugin.  Please use 'annotationProcessor' configuration instead.

我尝试在每个implementation之后添加annotationProcessor '.....',但没有成功摆脱错误.

I tried to add annotationProcessor '.....' after every implementation but no success to get rid of the error.

将android studio升级到最新版本(3.0)后会发生这种情况.

This happens after upgrading android studio to the latest version ( 3.0 ).

defaultConfig内添加includeCompileClasspath true并没有帮助:

    javaCompileOptions {
        annotationProcessorOptions {
            includeCompileClasspath true
        }
    }

有解决方案吗?

推荐答案

首先,升级后,gradle进行了一些更改.

First of all, after upgrading there are a few changes to gradle.

重要的是升级到最新的gradle版本以解决此问题.

Its important to upgrade to the latest gradle version to fix that.

这意味着您需要为当前的构建gradle添加正确的版本

That means that you need to add the proper version for your build gradle which is currently

 dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
 }

下一步是删除不再需要的android-apt.

the next step is to remove your android-apt which is not longer needed.

足以只包含apply plugin: 'com.android.application'

您已经做到了,请更改您的依赖项

Onec you have done that, change your dependencies from

compileimplementationaptannotationProcessortestCompileandroidTestImplementation

如果这样做会使缓存无效并重新启动,这是非常重要的.

If you have done that invalidate your cache and restart which is very important.

然后它应该可以工作.

您可以在以下位置使用最新版本找到有效的gradle文件

You can find a working gradle file using the latest version at

应用程序build.gradle 项目build.gradle

p/s:对于许多仍在使用Realm旧版本的人,

p/s : For many people still use Realm old version,

由于旧版本仍使用"android-apt",请更新至最新版本.

Please update to latest version since old version still use "android-apt".

这篇关于Android Studio 3.0注解处理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆