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

jonathanrz
  • 4,206
  • 6
  • 35
  • 58
  • 5
    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. – oldergod Sep 27 '16 at 02:36

11 Answers11

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.

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
Jacques Koorts
  • 1,819
  • 1
  • 17
  • 10
  • 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. – jonathanrz Aug 02 '16 at 01:18
  • 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.2 – Jacques Koorts Aug 04 '16 at 07:02
  • 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: https://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. – jonathanrz Aug 04 '16 at 13:51
  • 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) – Jacques Koorts Aug 08 '16 at 09:50
  • If I disable jack I can't compile with java 8. But I will try to solve those problems and get back to jack. – jonathanrz Aug 08 '16 at 17:01
  • 19
    "Annotation Processors" does not exist in Android Studio 2.1.2 – Johann Sep 06 '16 at 12:40
  • 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:52 – Jacques Koorts Sep 08 '16 at 06:29
  • 2
    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. – lilienberg Sep 09 '16 at 06:14
  • I took a [screenshot of the pane in Android Studio 2.2.1](http://imgur.com/a/N6AjI). There doesn't seem to be a section for annotation processors. What am I missing? – Apoorv Khatreja Oct 12 '16 at 21:02
  • 11
    @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". – P.Bra Oct 21 '16 at 16:12
  • 14
    You also can find it with project opened at "File" > "Other Settings" > "Default Settings..." – KWA Dec 12 '16 at 13:36
  • 23
    There is no such thing as **Compiler > Annotation Processors** in Android Studio 2.3. – IgorGanapolsky Dec 30 '16 at 14:43
  • 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 cannot – Krease May 01 '18 at 23:47
54
  1. Close all your AndroidStudio Project
  2. See enter image description here

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

Bill
  • 1,268
  • 14
  • 14
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!

Tudor
  • 1,510
  • 1
  • 18
  • 17
  • 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. – Jürgen 'Kashban' Wahlmann Jul 09 '17 at 06:47
  • in your gradle file you must change apt with annotationProcessor. For example apt "org.androidannotations:androidannotations:$AAVersion" -> annotationProcessor "org.androidannotations:androidannotations:$AAVersion"..... https://stackoverflow.com/questions/42622060/annotationprocessor-and-apt-configure-equivalent – Tudor Jul 21 '17 at 09:14
  • 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. – Chad Schultz Oct 22 '19 at 02:24
  • @ChadSchultz are you using Java or Kotlin? for Kotlin you must add kapt(kotlin annotation processor) to gradle as a dependency – Tudor Oct 22 '19 at 08:02
23

https://stackoverflow.com/a/38698186/4024146

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

Community
  • 1
  • 1
mtrakal
  • 6,121
  • 2
  • 25
  • 35
  • 2
    This right here solved my problem. Doing the silly "remove from start screen" hack didn't work! – Ian Apr 16 '17 at 20:44
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.

Maalevolent
  • 472
  • 1
  • 5
  • 12
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.

Neo Tran
  • 101
  • 1
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.

Bri6ko
  • 1,858
  • 1
  • 18
  • 29
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'
Fazal Hussain
  • 1,129
  • 12
  • 28
0

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

TooCool
  • 10,598
  • 15
  • 60
  • 85
0

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

android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }
}
e lwanga
  • 65
  • 7
-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.

KingKongCoder
  • 600
  • 4
  • 15