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

查看:95
本文介绍了为现有项目启用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

从磁盘重新导入项目.

使缓存/重启无效

但是,即使执行了上述步骤,也不会为我当前的应用生成注释.我还尝试了 this

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/文件夹中创建一个editor.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天全站免登陆