简体   繁体   中英

Android studio 3.1 not recognizing jar annotation processing

I'm trying to implement my own annotation processor in my android studio project. All is working well and compiling until I add this simple line to build.gradle dependencies block:

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

At that point I get this error when compiling:

Could not find :processor:. Required by: project :app Search in build.gradle files

I've followed endless tutorials and nothing seems to help. I've just recently upgraded to AS 3.1 and thinking maybe it relates?

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)

在此处输入图片说明

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:

在此处输入图片说明

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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