Reputation: 21
I want to write a demo using Java annotation processor in Android Studio, like ButterKnife. And I want to print some informations in process() method to know it has exactly run. I use System.out.println() and Messager.printMessage, but I don't know how to display these informations in Android Studio like Logcat.
@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment roundEnvironment) {
System.out.println("BindingProcessor is running!!!");
messager.printMessage(Diagnostic.Kind.WARNING, "BindingProcessor is running!!!");
return false;
}
And add my build output window informations:
Executing tasks: [:25-processor:assemble, :25-processor:testClasses]
:25-annotations:compileJava UP-TO-DATE
:25-processor:compileJava UP-TO-DATE
:25-processor:processResources UP-TO-DATE
:25-processor:classes UP-TO-DATE
:25-processor:jar UP-TO-DATE
:25-processor:assemble UP-TO-DATE
:25-processor:compileTestJava NO-SOURCE
:25-processor:processTestResources NO-SOURCE
:25-processor:testClasses UP-TO-DATE
BUILD SUCCESSFUL in 0s
4 actionable tasks: 4 up-to-date
I got the messages in one project, but in the other project, I got the other problem. I checked out the build out windows, in the first correct project, the messages showed below :compileDebugJavaWithJava message, but in the other project, I got the information below but no process messages:
> Task :app:compileDebugJavaWithJavac
Gradle may disable incremental compilation as the following annotation processors are not incremental: lib-compiler.jar (project :lib-compiler).
Consider setting the experimental feature flag android.enableSeparateAnnotationProcessing=true in the gradle.properties file to run annotation processing in a separate task and make compilation incremental.
Upvotes: 1
Views: 1652
Reputation: 1059
If you use a java lib, check the configure of the path
The Annotation Processor should register in
path-to-lib\src\main\resources\META-INF\services\javax.annotation.processing.Processor
with the full type name, egcn.djzhao.compiler.AnnotationProcessor
Upvotes: 0
Reputation: 2988
An annoatation processor runs during the build phase, not at runtime. The logcat window in Android Studio shows the debug log of a connected device at runtime.
To view messages printed out, you need to switch to the Build window (View -> Tool windows -> Build). All messages pertaining to the build phase are sent here.
I believe that the warning you mention, is simply a warning, it shouldn't impact your annotation processor. Perhaps you haven't added the appropriate annotation, which is why you receive no output.
Upvotes: 1
Reputation: 8371
Your messages will not print on the console, but on the build section. That's because the annotation processor runs on the build process. Example:
Upvotes: 0