Search code examples
javaandroidgradleannotationsandroid-apt

Android apt updating from 1.4 to 1.7 version


Hi I wanted to upgrade android-apt in my project from version 1.4 to 1.7

Currently I'm using Google auto-service 1.0-rc2, so all what I had to do is putting @AutoService(Processor.class) annotation in my annotation processor class.

After updating android-apt to 1.7 version my annotation processor stopped working. It seem it is not called during build.

I thought that auto-service may be the issue. So I made resources/META-INF/services/javax.annotation.processing.Processor file with content

pl.edu.radomski.navigator.NavigatorAnnotationProcessor

Sadly it didn't helped at all.

If you want to see the code with android-apt 1.4 and auto-service 1.0-rc2 it is available here

Is there any simple way to upgrade android-apt and keep the processor working?

Is this auto-service 1.0-rc2 fault or something is wrong with android-apt?


Solution

  • In 1.7 a change was made to not automatically build a dependent project that is set as apt, due to unwanted side effects affecting build order.

    In 1.8 I'll probably have a better way to support it, but in the mean time you can configure the apt block to specify that your processor should be run like this:

    apt {
     processor "pl.edu.radomski.navigator.NavigatorAnnotationProcessor"
    }
    

    Note that is only needed in the case your processor is in the same project as your app or library. The reason is that the file in META-INF/services is not read by javac in this setup because the project isn't packaged at that point. Explicitly adding a processor statement will add the processor that javac otherwise would not discover.