简体   繁体   English

Android Studio 3.1无法识别jar批注处理

[英]Android studio 3.1 not recognizing jar annotation processing

I'm trying to implement my own annotation processor in my android studio project. 我正在尝试在我的android studio项目中实现自己的注释处理器。 All is working well and compiling until I add this simple line to build.gradle dependencies block: 一切运行良好并进行编译,直到将以下简单行添加到build.gradle依赖关系块中:

dependencies {
   .
   .
   .
   annotationProcessor(':processor')
}

At that point I get this error when compiling: 那时我在编译时收到此错误:

Could not find :processor:. 找不到:processor:。 Required by: project :app Search in build.gradle files 需要的人:project:app在build.gradle文件中搜索

I've followed endless tutorials and nothing seems to help. 我遵循了无休止的教程,似乎无济于事。 I've just recently upgraded to AS 3.1 and thinking maybe it relates? 我最近刚刚升级到AS 3.1,并且可能与它有关?

Here is the project structure: (mind you - here I add the annotation processor as a jar file. I've also attached an image trying to do it as a different module and same result) 这是项目结构:(请注意-在这里,我将注释处理器添加为jar文件。我还附加了尝试将其作为不同模块和相同结果的图像)

在此处输入图片说明

Here is a different I'm trying to add it - creating the annotation processor in the same project with a different module and still no go: 这是我尝试添加的另一种方法-在同一项目中使用不同的模块创建注释处理器,但仍然行不通:

在此处输入图片说明

Some extra info in pics... Project structure: 图片中的一些额外信息...项目结构:

在此处输入图片说明

app.build: app.build:

在此处输入图片说明

processor.build: processor.build:

在此处输入图片说明

annotation: 注解:

在此处输入图片说明

MainActivity: 主要活动:

在此处输入图片说明

Processor implementation: 处理器实现:

在此处输入图片说明

If you have everything inside the same artifact, — annotation processor, it's annotations and library classes, used by processor users, Android Gradle plugin requires you to declare two dependencies on the same artifact: 如果所有内容都在同一工件(即注释处理器)中,即处理器用户使用的注释和库类,则Android Gradle插件需要您声明同一工件上的两个依赖关系:

annotationProcessor project(':processor')
compile project(':processor')

or 要么

annotationProcessor files('libs/processor.jar')
compile files('libs/processor.jar')

Note, that such setup might become unsupported in future. 请注意,将来可能不再支持这种设置。 It is advisable to split your processor in separate module and make it depend on the rest of code. 建议将处理器拆分为单独的模块,并使其依赖于其余代码。 After doing so you will be able to declare dependencies like this: 这样做之后,您将能够像这样声明依赖项:

annotationProcessor project(':processor') // processor-only jar
compile project(':processor-api') // annotations and classes for user code

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM