enable Annotation Processors option in Android Studio 2.2
Asked Answered
V

11

48

I'm trying to use java 8 in my project and for that I added the jack compiler.

After enabling jack I started having problems with libraries that use Annotation Processing and looking in the web I read that I need android studio 2.2 and com.android.tools.build:gradle:2.2.0-alpha6 to compile libraries that generate code from annotations.

I download Android Studio 2.2 preview 6 and converted my project to it. And after that I discovered that the apt gradle plugin is not supported anymore and then I needed to change every dependency that use apt to the use the new annotationProcessor option.

Ex:

apt "org.projectlombok:lombok:$rootProject.lombokVersion"

to

annotationProcessor "org.projectlombok:lombok:$rootProject.lombokVersion"

Now if I use "make project" the project is compiled without problems, but if I try to execute it I have errors with the code that should be generated by the annotations.

Also when I open the project I receive a warning from the lombok plugin "Annotation processing seems to be disabled for the project". When I open the project settings and go to "Build -> Compiler" I can't find Annotation Processors.

So, my question is: How can I enable Annotation Processors in Android Studio 2.2? This feature was disabled? If yes, how can I generate the code from annotations?

--EDIT-- I'm making a PullRequest to change the project to compile with Java8, you can check the PR here: https://github.com/jonathanrz/myexpenses-android/pull/57

Vitriolic answered 28/7, 2016 at 17:8 Comment(1)
Jacques Koorts's answer is great. The key is to close the current project because Annotation Processors are not displayed in Gradle projects. You need to access the Compiler menu from the root.Persuasion
M
102

Close the project. In the "Welcome to Android Studio" dialog click "Configure" in the bottom right corner.

Then,

Settings > Build, Execution, Deployment > Compiler > Annotation Processors. Tick 'Enable annotation processing'.

If that does not work. Delete the project from "Welcome to Android Studio" dialog and open from new.

Worked for me.

Madox answered 1/8, 2016 at 11:52 Comment(13)
Thanks for you reply :). It solved the lombok warning but aren't executing the annotation processing. I updated my question with a link to the repository if you want to do any tests.Vitriolic
I cloned your project and picked up a few things: 1. Don't commit IDE auto generated files eg. .idea so check your gitignore. 2. App runs fine on my Android Studio 2.1.2Madox
thanks for the info about the idea files. About the project, the master branch are running without problem. This PR has the code to enable java8: github.com/jonathanrz/myexpenses-android/pull/57. Ps: the PR has code from another PR, I will merge the another PR soon, so the diff will be more simple.Vitriolic
Can you disable the jack compiler and take it from there? Doing that shows me new errors like getting latest gradle (you don't have the latest gradle plugin or wrapper configured)Madox
If I disable jack I can't compile with java 8. But I will try to solve those problems and get back to jack.Vitriolic
"Annotation Processors" does not exist in Android Studio 2.1.2Politburo
I'm using stable 2.1.3 and I have it. If you still don't see it see my answer at Aug 1 at 11:52Madox
I also searched for the annotation processor option in the settings and could not find it. My mistake always was to click on the "Compiler" option which is not a folder. Just above there is another "Compiler" option with subelements also containing the annotation processors.Holds
I took a screenshot of the pane in Android Studio 2.2.1. There doesn't seem to be a section for annotation processors. What am I missing?Yamada
@appoorv-Khatreja You can not find it, because you are on a current project as well said by Jacques Koorts. So close your current project. Then open the Configure/Settings menu in Android Studio (on bottom right). Then choose Build,Execution,Deployment/Compiler then Annocation Processors and then you can check "Enable annotation processing".Erg
You also can find it with project opened at "File" > "Other Settings" > "Default Settings..."Dibb
There is no such thing as Compiler > Annotation Processors in Android Studio 2.3.Overarch
Look at the other answers below - you don't need to close your project. Also note that there are two "Compiler" labels in the settings dialog - one can be expanded (this is where the setting is), the other cannotOrnamented
B
54
  1. Close all your AndroidStudio Project
  2. See enter image description here

  3. Click Configure-->Setting See enter image description here

Bezoar answered 12/1, 2017 at 5:51 Comment(0)
V
33

You can enable Annotation Processors without closing your project in Android Studio 2.3:

File -> Other Settings -> Default Settings

enter image description here

Build, Execution, Deployment -> Compiler -> Annotation Processors -> 
Enable annotation processing.

enter image description here Don't forget to clean, build, invalidate and restart after that.
Cheers!

Vertumnus answered 9/5, 2017 at 6:28 Comment(4)
Not working for me. I try to run org.AndroidAnnotations which was fine with APT but I cannot get it to work with Android Annotation Processor. The Processor simply does not kick in.Crosstie
in your gradle file you must change apt with annotationProcessor. For example apt "org.androidannotations:androidannotations:$AAVersion" -> annotationProcessor "org.androidannotations:androidannotations:$AAVersion"..... #42622560Vertumnus
This isn't working for me. At first I thought it was, but the red lines came back. The errors go away when Android Studio is starting up, or immediately after running tests, but then they quickly return. Even after copying over a compiler.xml file with the correct setting set, I still experience the error. No solution so far.Conductance
@ChadSchultz are you using Java or Kotlin? for Kotlin you must add kapt(kotlin annotation processor) to gradle as a dependencyVertumnus
R
23

https://mcmap.net/q/352004/-enable-annotation-processors-option-in-android-studio-2-2

and after do: File > Invalidate Caches / Restart... > Invalidate and Restart

Ridden answered 23/10, 2016 at 3:54 Comment(1)
This right here solved my problem. Doing the silly "remove from start screen" hack didn't work!Darondarooge
F
7

Open compiler.xml in the .idea folder. I had the following:

<annotationProcessing>
  <profile default="true" name="Default" enabled="false">
    <processorPath useClasspath="true" />
  </profile>
</annotationProcessing>

I simply changed enable to true and re-opened project.

Flowerage answered 1/5, 2017 at 14:27 Comment(0)
S
4
  1. Close your project.
  2. Settings > Build, Execution, Deployment > Compiler > Annotation Processors. Check 'Enable annotation processing'.
  3. Open your project.
  4. File > Invalidate Caches / Restart... > Invalidate and Restart

Wait for the process completely, then everything will be fine.

Shivers answered 18/4, 2017 at 19:39 Comment(0)
H
1

Adding to @Jacques Koorts and @mtrakal

If you can't get to the "Welcome to Android Studio" screen. Try File -> Close Project instead of clicking the X icon. Then you'll get the "Welcome to Android Studio" screen and you'll see the gear in the bottom right. Follow the accepted answer after that and possibly the cache invalidation.

Haynes answered 8/1, 2017 at 18:58 Comment(0)
A
1

This Answer for those who face this problem in the future

For Kotlin

Add kapt plugin

apply plugin: 'kotlin-kapt'
implementation 'com.google.dagger:dagger:2.21'
kapt 'com.google.dagger:dagger-compiler:2.21'

For Java

implementation 'com.google.dagger:dagger:2.21'
annotationProcessor 'com.google.dagger:dagger-compiler:2.21'
Available answered 1/3, 2019 at 12:17 Comment(1)
useful answer (y) specially for kotlinUlulate
T
0

Stuped but worked for me, try to change the library version in my case I upgraded to 1.4.1

Tore answered 13/8, 2017 at 18:24 Comment(0)
T
0

personally i will force my way through adding this to your build.gradle(Module:app) file

android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }
}
Tannen answered 31/1, 2021 at 20:52 Comment(0)
E
-1

Sometimes the annotate option will be grayed out if the project is not integrated into version control. So goto VCS->Enable version control integration then voila you will see the annotate option and can see the author name beside the line numbers on the editor.

Enjoin answered 12/12, 2017 at 15:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.