問題描述
我正在嘗試在我的項目中使用 java 8,為此我添加了 jack 編譯器.
I'm trying to use java 8 in my project and for that I added the jack compiler.
啟用杰克后,我開始遇到使用注釋處理的庫的問題,并在網上查看我讀到我需要 android studio 2.2 和 com.android.tools.build:gradle:2.2.0-alpha6 來編譯生成的庫注釋中的代碼.
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.
我下載了 Android Studio 2.2 preview 6 并將我的項目轉換為它.之后我發現不再支持 apt gradle 插件,然后我需要將每個使用 apt 的依賴項更改為使用新的 annotationProcessor 選項.
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.
例如:
apt "org.projectlombok:lombok:$rootProject.lombokVersion"
到
annotationProcessor "org.projectlombok:lombok:$rootProject.lombokVersion"
現在,如果我使用make project",項目編譯沒有問題,但如果我嘗試執行它,我應該由注釋生成的代碼出現錯誤.
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.
此外,當我打開項目時,我收到來自 lombok 插件的警告項目的注釋處理似乎已禁用".當我打開項目設置并轉到構建 -> 編譯器"時,我找不到注釋處理器.
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.
所以,我的問題是:如何在 Android Studio 2.2 中啟用注釋處理器?這個功能被禁用了?如果是,如何從注解生成代碼?
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?
--編輯--我正在制作一個 PullRequest 來更改項目以使用 Java8 編譯,您可以在此處查看 PR:https://github.com/jonathanrz/myexpenses-android/pull/57
--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
推薦答案
關閉項目.在Welcome to Android Studio"對話框中點擊右下角的Configure".
Close the project. In the "Welcome to Android Studio" dialog click "Configure" in the bottom right corner.
那么,
設置 > 構建、執行、部署 > 編譯器 > 注釋處理器.勾選啟用注釋處理".
Settings > Build, Execution, Deployment > Compiler > Annotation Processors. Tick 'Enable annotation processing'.
如果這不起作用.從Welcome to Android Studio"對話框中刪除項目并從新打開.
If that does not work. Delete the project from "Welcome to Android Studio" dialog and open from new.
為我工作.
這篇關于在 Android Studio 2.2 中啟用注釋處理器選項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!