之前做后端開發(fā)透敌,經(jīng)常使用Lombok描扯,簡潔的代碼定页,沒有比這更優(yōu)雅了。
而在Android的開發(fā)中绽诚,還是依舊使用傳統(tǒng)方式就不斷的生成get和set代碼典徊。
如今的系統(tǒng),業(yè)務(wù)變更太快了恩够,三天兩頭不是數(shù)據(jù)庫加字段卒落,就是前端加顯示。
如此繁瑣的過程蜂桶,還是比較痛苦的儡毕。當然使用過lombok插件的都知道,一切都很簡單扑媚。
言歸正傳腰湾,Android Studio如何使用呢?如下:
首先疆股,安裝插件:
- 打開 File > Settings > Plugins
- 點擊 Browse repositories...
- 搜索 Lombok Plugin
- 點擊安裝 Install plugin
- 重啟 Android Studio
然后就是直接在Android系統(tǒng)中使用了费坊,如下:
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.6'
annotationProcessor 'org.projectlombok:lombok:1.18.6'
}
設(shè)置default setting:
- File->Other Settings->Default Settings
- Expand Build, Execution, Deployment
- Expand Compiler
- In Annotation Processors check Enable annotation processing
如果打開項目時有報錯:
Annotation processing seems to be disabled for the project X
解決方案:找到.idea下面的compiler.xml,修改如下:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile default="true" name="Default" enabled="true" />
</annotationProcessing>
</component>
</project>