注释处理器不工作 - 没有创建文件 [英] Annotation processor not working - no files are created

查看:36
本文介绍了注释处理器不工作 - 没有创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在搜索了为什么我自己的注释处理器在我的一个项目中不起作用的原因.设置如下所示:

I've now searched for reasons why my own annotation processor is not working in ONE of my projects. Setup looks like following:

  • Android Studio 2.3.3
  • gradle 构建工具 2.3.3
  • android studio 中启用了注解处理器

我尝试了常见的解决方案:

I tried the common solutions:

  • 从 Android Studio 最近中删除我的项目
  • 使缓存无效并重新启动android studio
  • 再次将我的项目导入android studio(确保之前启用了注释处理)

没有任何帮助.我在另一个项目中进行了注释处理,并将其与这个项目进行了比较.唯一的区别是我在另一个项目中使用了 kotlin.所以我只是在我的新项目中添加了以下内容:

Nothing helps. I have annotation processing working in another project and compared it with this one. Only difference is that I'm using kotlin in the other project. So I just added following to my new project:

Kotlin 和 apply plugin: 'kotlin-android' 突然注释处理起作用了.为什么?我还没有找到任何关于此的信息,但在我的情况下,如果不应用 kotlin 插件,注释处理不再起作用(在旧的 android 版本中它肯定会起作用,但不确定它何时损坏)..

Kotlin and apply plugin: 'kotlin-android' and suddenly annotation processing works. Why? I have not found anything about this yet but in my case, annotation processing does not work anymore (in older android versions it did for sure, not sure when it broke though) without applying the kotlin plugin...

据我所知,我不必应用注释处理器插件,对吗?我还缺什么吗?

As far as I know I don't have to apply the annotation processor plugin, correct? Am I missing something else?

示例build.gradle:

apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'kotlin-android'

android {

    if (project.hasProperty('setup.compileSdk'))
    {
        compileSdkVersion setup.compileSdk
        buildToolsVersion setup.buildTools
        defaultConfig {
            minSdkVersion setup.minSdk
            targetSdkVersion setup.targetSdk
        }
    }
    else
    {
        compileSdkVersion 26
        buildToolsVersion "26.0.1"
        defaultConfig {
            minSdkVersion 21
            targetSdkVersion 26
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dataBinding.enabled = true

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    retrolambda {
        jvmArgs '-noverify'
    }
}

dependencies {

    // dependencies...

    compile project(':bundleargs-annotation')
    annotationProcessor project(':bundleargs-processor')
}

推荐答案

  1. Android Studio - 文件 - 关闭项目
  2. 配置 - 设置 - 构建、执行、部署 - 编译器 - 注释处理器 - 启用注释处理.
  3. 打开项目 - 构建 - 重建项目.

如果没有帮助 - 重新创建项目.

If it doesn't help - recreate the project.

这篇关于注释处理器不工作 - 没有创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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