web-dev-qa-db-ja.com

Retrolambda:Retrolambdaでラムダ式を使用するとLintがクラッシュする

gradle-retrolambda プラグインとともに 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()
    }
}
43
Denis Itskovich

特別なlombokバージョン をlintと共に使用できます。lintは、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ファイル。それならうまくいくはずです。

47
WonderCsabo

この問題を説明するGitHubの問題があります: https://github.com/evant/gradle-retrolambda/issues/96

問題のコメントの1つには、lintが実際にレトロラムダで機能したことはなく、最新のlintバージョンでは、ファイルの残りを単にスキップするのではなく、「大声で失敗する」ことが記載されていますラムダが見つかりました。

これを考慮して、2つのオプションがあるようです。 1つは、質問で述べたようにlintを無効にするだけです。もちろん、これの問題は、コードの残りの部分をスキャンするlintの利点を失うことです。 2番目のオプションは、lintバージョンをロールバックして、「大音量で失敗する」のではなく、ラムダ関連のソースのチェックをスキップすることです。このようにして、lintは残りのアプリケーションソースコードをスキャンできます。

GitHubの問題によると、lintのバージョンを24.0.1(別のバージョンの可能性があります)から24.0.0にロールバックすると、問題が解決するようです。この情報は問題(回答の最初に掲載されているリンク)にあります。

19
Willis