问题
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:
- Android Studio - File - Close Project
- Configure - Settings - Build, Execution, Deployment - Compiler - Annotation Processors - Enable annotation processing.
- Open Project - Build - Rebuild Project.
If it doesn't help - recreate the project.
回答2:
Add the following in build.gradle file of the project using annotation
plugins { id 'kotlin-kapt' }
Add annotation processor dependency as following
dependencies { implementation project('::bundleargs-annotation') kapt project(':bundleargs-processor') }
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