Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly set up Lombok in Android Studio 3.0

I would like to know what am I doing wrong in the Lombok setup for Android Studio 3.0 Beta 2?

That's how my Gradle build file looks like:

buildscript {
    repositories {
        mavenCentral()
        jcenter()
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "io.franzbecker:gradle-lombok:1.10"
        classpath 'com.android.tools.build:gradle:2.3.3'
    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "MyAppName"
        gdxVersion = '1.7.0'
    }

    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    }
}

project(":desktop") {
    apply plugin: "java"


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
    }
}

project(":core") {
    apply plugin: "io.franzbecker.gradle-lombok"
    apply plugin: "java"

    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compileOnly "org.projectlombok:lombok:1.16.18"
    }
}

tasks.eclipse.doLast {
    delete ".project"
}

I have installed the lombok plugin, and lombok stuff also shows up properly in the IDE, but when I want to build the project Gradle can not find the getters/setters created by Lombok. I tried to follow the tutorials from https://projectlombok.org/setup/android and other stack overflow pages about this setup, but nothing worked. In Android Studio 2.3 I couldn't even enable the annotation processing properly, that's why I updated to the latest beta version, where that at least works.

like image 617
gyurix Avatar asked Aug 22 '17 08:08

gyurix


People also ask

Can I use Lombok in Android Studio?

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.

How do I add Lombok jar to my project?

Adding the Lombok Plugin in IDE (Eclipse) Downloaded jar from https://projectlombok.org/download or use the jar which is downloaded from your maven build. Execute command in terminal: java -jar lombok. jar. This command will open window as show in the picture below, install and quit the installer and restart eclipse.

What is Lombok annotation processing?

Lombok as an Annotation ProcessorJava allows application developers to process annotations during the compilation phase; most importantly, to generate new files based on an annotation. As a result, libraries like Hibernate allow developers to reduce the boiler-plate code and use annotations instead.


2 Answers

I have the same issue. At last I end up with this solution -

compileOnly 'org.projectlombok:lombok:1.16.18'
compileOnly 'javax.annotation:javax.annotation-api:1.3.1'
annotationProcessor 'org.projectlombok:lombok:1.16.18'
like image 182
Anirban Avatar answered Sep 19 '22 16:09

Anirban


You need to use new annotationProcessor instead of apt : Gradle migration annotationProcessor

annotationProcessor "org.projectlombok:lombok:1.16.18"

I had the same problem as you and now it works.

like image 26
Maelig Avatar answered Sep 21 '22 16:09

Maelig