Search code examples
javaandroidannotation-processingannotation-processor

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)

enter image description here

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:

enter image description here

Some extra info in pics... Project structure:

enter image description here

app.build:

enter image description here

processor.build:

enter image description here

annotation:

enter image description here

MainActivity:

enter image description here

Processor implementation:

enter image description here


Solution

  • 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