How to set up compile library in android studio. LOMBOK

给你一囗甜甜゛ 提交于 2019-11-30 08:44:43

With Android Studio 1.1.0, I couldn't find a consolidated set of instructions for adding Lombok that worked for me. That includes Lombok's own setup page: http://projectlombok.org/setup/android.html

Here's everything I had to do to get it working (on OS X):

  • Install Lombok plugin in Android Studio
    • Android Studio > Preferences > Plugins
    • Click on Browse repositories...
    • Search for Lombok Plugin
    • Click on Install plugin
    • Restart Android Studio
  • Add to the android/dependencies block in app/build.gradle: provided 'org.projectlombok:lombok:1.16.2'
    • See search.maven.org for latest version, as lombok's instructions don't update as they release new versions
    • I assume the subprojects approach in build.gradle in the project root (from Олександр Самсонов's answer) works also, but it appears that requires moving the configuration from app/build.gradle (you aren't allowed to further extend the configuration in the subprojects). I didn't want to move the entire android configuration, so I kept it in the app/build.gradle instead.
  • Create a lombok.config file in the root of the project containing two lines: lombok.anyConstructor.suppressConstructorProperties = true lombok.addGeneratedAnnotation = false

The ability to do this was just added to the v0.8 Android-Gradle plugin, which you can use if you're running Android Studio 0.4.3 (which is available on the canary update channel).

It's mentioned in the release notes and a thread on the adt-dev mailing list

You specify it like this:

dependencies {
    provided 'org.projectlombok:lombok:1.12.2'
}

I've filed bug https://code.google.com/p/android/issues/detail?id=65216 to request the ability to edit this through the Dependencies panel in the Project Structure dialog; for the moment you have to edit your build.gradle file by hand to use this.

As for whether you can put it in the top-level build.gradle file to have it apply to all modules, I'm not certain. I tried putting it in the allprojects block, but Gradle told me that the default dependency handler didn't know what to do with it. So I'm guessing no, but if I get other information, I'll update this answer.

kaMChy

For Android Studio

  1. Go to File > Settings > Plugins
  2. Click on "Browse repositories..."
  3. Search for "Lombok Plugin"
  4. Click on "Install plugin"
  5. Restart Android Studio

I resolve this issue by changing gradle-wrapper.properties file in gradle folder. Now it looks like this:

#Sat Jan 25 02:59:06 EET 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-all.zip

and in main build.gradle file i can wrote this for lombok

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.8.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

subprojects {
    apply plugin: 'android'

    buildscript {
        repositories {
            mavenCentral()
        }
    }

    android {
        compileSdkVersion 19
        buildToolsVersion "19.0.0"

        defaultConfig {
            minSdkVersion 10
            targetSdkVersion 16
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                runProguard false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            }
        }
    }

    dependencies {
        compile 'com.android.support:appcompat-v7:+'
        provided 'org.projectlombok:lombok:1.12.2'
    }
}

Now in sub projects i don't need write many params for plugins or repositories and provided method works pretty fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!