简体   繁体   中英

enable Annotation Processors option in Android Studio 2.2

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

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.

  1. Close all your AndroidStudio Project
  2. See在此处输入图片说明

  3. Click Configure-->Setting See在此处输入图片说明

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

File -> Other Settings -> Default Settings

在此处输入图片说明

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

在此处输入图片说明 Don't forget to clean, build, invalidate and restart after that.
Cheers!

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

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

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.

  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.

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.

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'

Stuped但对我有用,在我升级到1.4.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.

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

android {
    ...
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath false
            }
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM