Annotation processor not working - no files are created

前提是你 提交于 2021-02-07 19:22:12

问题


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 build tools 2.3.3
  • annotation processor is enabled in android studio

I tried the common solutions:

  • remove my project from Android Studio recents
  • invalidate cache and restart android studio
  • import my project again into android studio (made sure that annotation processing is enabled before)

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 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?

Example 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:


  1. Android Studio - File - Close Project
  2. Configure - Settings - Build, Execution, Deployment - Compiler - Annotation Processors - Enable annotation processing.
  3. Open Project - Build - Rebuild Project.

If it doesn't help - recreate the project.




回答2:


  1. Add the following in build.gradle file of the project using annotation

     
         plugins {
             id 'kotlin-kapt'
         }
     
     
  2. Add annotation processor dependency as following

     
         dependencies {
             implementation project('::bundleargs-annotation')
             kapt project(':bundleargs-processor')
         }
  3. Clean > Build

These steps should trigger generated files under the below folder

build > generated > source > kapt > build variant


来源:https://stackoverflow.com/questions/45826037/annotation-processor-not-working-no-files-are-created

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