How to set up compile library in android studio. LOMBOK

前端 未结 4 1730
情话喂你
情话喂你 2020-12-31 06:35

Help me to set up comile dependencies in Android Studio in build.gradle. I mean that they not include into final APK.

this build.gradle works fine but i don\'t need

相关标签:
4条回答
  • 2020-12-31 06:58

    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
    0 讨论(0)
  • 2020-12-31 06:58

    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.

    0 讨论(0)
  • 2020-12-31 06:58

    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.

    0 讨论(0)
  • 2020-12-31 07:04

    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
    0 讨论(0)
提交回复
热议问题