问题
I am using Android studio 3.3 and trying to use Dagger2 in my project. However, the annotation processing does not work in it and the annotation classes are not generated.
I am add the library as follows to my gradle file.
implementation 'com.google.dagger:dagger:2.21'
annotationProcessor 'com.google.dagger:dagger-compiler:2.21'
I have also specified the annotationProcessorOptions
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath true
}
}
What have I tried:
Closing the project.
Going to Configure -> Settings -> Build, Execution and Deployment ->Compiler ->Annotation Processors and checked "Enable annotation processing"
Removing my project from the recent projects list
Re-importing the project from the disk.
Invalidate cache/restart
However, even after doing the above steps the annotations are not being generated for my current app. I have also tried this and this, but the steps in the second link do not seem to appear for my current project settings and the compiler option is greyed out. Is there a way I can enable them for my current app?
回答1:
the real solution is: 1 - create a compiler.xml in .idea/ folder and write that code in it.
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
</annotationProcessing>
</component>
</project>
2- invalidate and restart
回答2:
I resolved the issue myself. I had to do the whole process mentioned in the question all over again, restart the machine and clean rebuild the project. It worked fine after that. Hope this is helpful for anyone looking for a solution to a similar issue
来源:https://stackoverflow.com/questions/56289830/enable-annotation-processing-for-existing-projects-android-studio-3-3