为现有项目启用 Annotation 处理 Android studio 3.3 [英] Enable Annotation processing for existing projects Android studio 3.3

查看:27
本文介绍了为现有项目启用 Annotation 处理 Android studio 3.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Android studio 3.3 并尝试在我的项目中使用 Dagger2.但是,注释处理在其中不起作用,并且不会生成注释类.

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.

我将如下库添加到我的 gradle 文件中.

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'

我还指定了 annotationProcessorOptions

 javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }

我尝试了什么:

  1. 关闭项目.

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

从磁盘重新导入项目.

使缓存无效/重新启动

但是,即使在执行上述步骤之后,也不会为我当前的应用程序生成注释.我也试过 thisthis,但第二个链接中的步骤似乎没有出现在我当前的项目中设置和编译器选项显示为灰色.有没有办法为我当前的应用启用它们?

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 - 在 .idea/文件夹中创建一个 compiler.xml 并将该代码写入其中.

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- 失效并重启

这篇关于为现有项目启用 Annotation 处理 Android studio 3.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆