43

我正在尝试将retrolambdagradle-retrolambda插件一起使用。一般来说它工作正常,但是当我编译发布时,lint阶段失败并出现异常:

:playground.dagger:lintVitalReleaseFailed converting ECJ parse tree to Lombok for file D:\....\playground\dagger\MainActivity.java
java.lang.UnsupportedOperationException: Unknown ASTNode child: LambdaExpression
    at lombok.ast.ecj.EcjTreeVisitor.visitOther(EcjTreeVisitor.java:368)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:364)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:252)
    at lombok.ast.ecj.EcjTreeConverter.access$100(EcjTreeConverter.java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.visitMessageSend(EcjTreeConverter.java:1042)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:156)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:252)
    at lombok.ast.ecj.EcjTreeConverter.toBlock(EcjTreeConverter.java:397)
    at lombok.ast.ecj.EcjTreeConverter.access$1500(EcjTreeConverter.java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.visitMethodDeclaration(EcjTreeConverter.java:1241)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:152)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:252)
    at lombok.ast.ecj.EcjTreeConverter.access$100(EcjTreeConverter.java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.createNormalTypeBody(EcjTreeConverter.java:563)
    at lombok.ast.ecj.EcjTreeConverter$2.visitTypeDeclaration(EcjTreeConverter.java:486)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:48)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at lombok.ast.ecj.EcjTreeConverter.toTree(EcjTreeConverter.java:236)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:282)
    at lombok.ast.ecj.EcjTreeConverter.fillList(EcjTreeConverter.java:252)
    at lombok.ast.ecj.EcjTreeConverter.access$100(EcjTreeConverter.java:141)
    at lombok.ast.ecj.EcjTreeConverter$2.visitCompilationUnitDeclaration(EcjTreeConverter.java:441)
    at lombok.ast.ecj.EcjTreeVisitor.visitEcjNode(EcjTreeVisitor.java:264)
    at lombok.ast.ecj.EcjTreeConverter.visit(EcjTreeConverter.java:295)
    at com.android.tools.lint.EcjParser.parseJava(EcjParser.java:407)
    at com.android.tools.lint.client.api.JavaVisitor.visitFile(JavaVisitor.java:236)
    at com.android.tools.lint.client.api.LintDriver.checkJava(LintDriver.java:1491)
    at com.android.tools.lint.client.api.LintDriver.runFileDetectors(LintDriver.java:1026)
    at com.android.tools.lint.client.api.LintDriver.checkProject(LintDriver.java:882)
    at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:433)
    at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:374)
    at com.android.tools.lint.LintCliClient.run(LintCliClient.java:130)
    at com.android.build.gradle.internal.LintGradleClient.run(LintGradleClient.java:112)
    at com.android.build.gradle.internal.LintGradleClient$run.call(Unknown Source)
    at com.android.build.gradle.tasks.Lint.runLint(Lint.groovy:198)
    at com.android.build.gradle.tasks.Lint.this$4$runLint(Lint.groovy)
    at com.android.build.gradle.tasks.Lint$this$4$runLint$1.callCurrent(Unknown Source)
    at com.android.build.gradle.tasks.Lint.lintSingleVariant(Lint.groovy:173)
    at com.android.build.gradle.tasks.Lint$lintSingleVariant$0.callCurrent(Unknown Source)
    at com.android.build.gradle.tasks.Lint.lint(Lint.groovy:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:218)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:211)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:200)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:579)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:562)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:305)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:88)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
    at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:43)
    at org.gradle.tooling.internal.provider.BuildModelAction.run(BuildModelAction.java:30)
    at org.gradle.tooling.internal.provider.ConfiguringBuildAction.run(ConfiguringBuildAction.java:119)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:47)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:35)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:70)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:119)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:46)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:246)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

有什么可做的吗?当然,一个简单的工作/解决方法是禁用lint检查释放。但我正在寻找解决方案,允许保留lint.

以下是应用程序的模块build.gradle

apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.neenbedankt.android-apt'

configurations {
    apt
}

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    maven{
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
    compile 'de.greenrobot:eventbus:2.4.0'
    retrolambdaConfig 'net.orfjackal.retrolambda:retrolambda:1.8.1'
    apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
    provided 'org.glassfish:javax.annotation:10.0-b28'
}

build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        classpath 'me.tatarka:gradle-retrolambda:2.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
4

2 回答 2

47

您可以使用带有 lint 的特殊 lombok 版本,它不会抱怨 Java 8 的特性。

buildscript {
    repositories {
        jcenter()
        ...
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:<version>'
        classpath 'me.tatarka:gradle-retrolambda:<version>'
        classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
    }

    // Exclude the version that the android plugin depends on.
    configurations.classpath.exclude group: 'com.android.tools.external.lombok'
}

这样,即使使用最新版本的 Android Gradle 插件,您也可以在整个项目上继续运行 lint。

注意:如果您收到相同的错误,请尝试将上面的配置放入最顶层的build.gradle文件中。它应该工作。

于 2015-05-29T18:23:02.097 回答
19

有一个讨论这个问题的 GitHub 问题:https ://github.com/evant/gradle-retrolambda/issues/96

该问题中的一条评论提到lint实际上从未与 retrolambda 一起使用,而是使用最新lint版本,现在“大声失败”,而不是在遇到 lambda 时简单地跳过文件的其余部分。

考虑到这一点,似乎有两种选择。lint一,您可以像您在问题中提到的那样简单地禁用。当然,这样做的问题是您将失去lint扫描其余代码的好处。第二种选择是回滚您的lint版本,使其不再“大声失败”,而是简单地跳过检查与 lambda 相关的源;这样,lint仍然可以扫描您的应用程序源代码的其余部分。

lint根据 GitHub 问题,将您的版本从24.0.1(您可能有不同的版本)回滚到24.0.0似乎可以解决问题。您可以在问题中找到此信息(链接发布在答案的开头)。

于 2015-04-30T16:45:37.777 回答