Project Lombok
  • Features
    • Stable
    • Experimental
  • Community
    • Discuss / Help
    • Issues
    • Documentation for contributors
    • Contact the team behind Project Lombok
  • Order / Donate
  • How to use Install
    • Compilers
    • Javac
    • ECJ
    • Build tools
    • maven
    • gradle
    • ant
    • kobalt
    • IDEs
    • Eclipse
    • IntelliJ IDEA
    • Netbeans
    • MyEclipse
    • Spring Tool Suite
    • JBoss Developer Studio
    • Visual Studio Code
    • Platforms
    • Android
    • GWT
  • Download

Android

Android development with lombok is easy and won't make your android application any 'heavier' because lombok is a compile-time only library. It is important to configure your android project properly to make sure lombok doesn't end up in your application and waste precious space on android devices.

The instructions listed below are excerpts from The AndroidAnnotations project cookbook. You may wish to refer to that documentation for complete instructions; lombok is just the equivalent to androidannotations-VERSION.jar; there is no -api aspect.

Gradle

  • Make sure that the version of your android plugin is >= 0.4.3
  • Use the gradle-lombok plugin.
  • If you don't want to use the plugin, add Lombok to your application's dependencies block (requires Gradle v2.12 or newer):

    dependencies {
    	compileOnly "org.projectlombok:lombok:1.18.26"
    }

Android Studio

Follow the previous instructions (Gradle). In addition to setting up your gradle project correctly, you need to add the Lombok IntelliJ plugin to add lombok support to Android Studio:

  • Go to File > Settings > Plugins
  • Click on Browse repositories...
  • Search for Lombok Plugin
  • Click on Install plugin
  • Restart Android Studio

Modify your application's dependencies block:

dependencies {
	compileOnly 'org.projectlombok:lombok:1.18.26'
	annotationProcessor 'org.projectlombok:lombok:1.18.26'
}

Eclipse

In eclipse, create a 'lightweight' lombok jar that contains only the annotations by running:

java -jar lombok.jar publicApi
Then, add the lombok-api.jar file created by running this command to your android project instead of the complete lombok.jar, and, as usual, install lombok into eclipse by double-clicking lombok.jar.

Maven

You should be able to just follow the normal integrate lombok with maven instructions.
Note that if you use android, eclipse, and maven together you may have to replace lombok.jar in your eclipse android project's build path (which you can modify in that project's properties page) with lombok-api.jar, as produced in the procedure explained for Eclipse, above.

Ant

  • Find build.xml in ${ANDROID_SDK_ROOT}/tools/ant/build.xml and copy the -compile target into the paste buffer.
  • Copy this to the build.xml of your own project, right before the <import file="${sdk.dir}/tools/ant/build.xml"> line.
  • Create a compile-libs directory in your own project and copy the complete lombok.jar to it.
  • Now modify the <classpath> entry inside the <javac> task in the -compile target you just copied:
    add <fileset dir="compile-libs" includes="*.jar" /> to it.

credits | Copyright © 2009-2023 The Project Lombok Authors, licensed under the MIT license.