Enable Annotation processing for existing projects Android studio 3.3

China☆狼群 提交于 2021-01-28 12:05:28

问题


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:

  1. Closing the project.

  2. Going to Configure -> Settings -> Build, Execution and Deployment ->Compiler ->Annotation Processors and checked "Enable annotation processing"

  3. Removing my project from the recent projects list

  4. Re-importing the project from the disk.

  5. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!