基于Kotlin的Gradle脚本的Android Lint失败

时间:2019-01-02 18:33:35

标签: android gradle kotlin android-gradle gradle-kotlin-dsl

将我的 build.gradle 脚本迁移到 build.gradle.kts 之后,我现在看到皮棉对我来说是失败的。我创建了一个临时项目,试图重现该问题,但没有任何效果(该项目运行时皮棉完美无缺)。因为我对皮棉的运行方式不是很了解,但是在深入研究时,我想看看是否有人遇到了这个问题并知道可能会发生什么。

我怀疑是在构建过程中添加了引起问题的东西,但是直到我确定问题之前,还是会希望得到一些反馈。

科林版本: 1.2.60

AGP版本: 3.2.1

KGP版本: 1.2.60

org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments: Couldn't get delegate for class
    at org.jetbrains.kotlin.asJava.builder.LightClassDataHolderKt.findDelegate(LightClassDataHolder.kt:100)
    at org.jetbrains.kotlin.asJava.builder.LightClassDataHolder$ForClass$findDataForClassOrObject$1.invoke(LightClassDataHolder.kt:40)
    at org.jetbrains.kotlin.asJava.builder.LightClassDataHolder$ForClass$findDataForClassOrObject$1.invoke(LightClassDataHolder.kt:34)
    at org.jetbrains.kotlin.asJava.builder.LightClassDataHolderImpl.findData(LightClassDataHolder.kt:83)
    at org.jetbrains.kotlin.asJava.builder.LightClassDataHolderImpl.findData(LightClassDataHolder.kt:79)
    at org.jetbrains.kotlin.asJava.builder.LightClassDataHolder$ForClass$DefaultImpls.findDataForClassOrObject(LightClassDataHolder.kt:40)
    at org.jetbrains.kotlin.asJava.builder.LightClassDataHolderImpl.findDataForClassOrObject(LightClassDataHolder.kt:79)
    at org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration.findLightClassData(KtLightClassForSourceDeclaration.kt:95)
    at org.jetbrains.kotlin.asJava.classes.KtLightClassForSourceDeclaration.getLightClassData(KtLightClassForSourceDeclaration.kt:93)
    at org.jetbrains.kotlin.asJava.classes.KtLazyLightClass.getOwnFields(KtLazyLightClass.kt:28)
    at com.intellij.psi.impl.source.ClassInnerStuffCache.getAllFields(ClassInnerStuffCache.java:104)
    at com.intellij.psi.impl.source.ClassInnerStuffCache.lambda$getFields$1(ClassInnerStuffCache.java:41)
    at com.intellij.psi.util.CachedValuesManager.lambda$getCachedValue$0(CachedValuesManager.java:140)
    at com.intellij.psi.impl.PsiCachedValueImpl.doCompute(PsiCachedValueImpl.java:49)
    at com.intellij.util.CachedValueBase.getValueWithLock(CachedValueBase.java:222)
    at com.intellij.psi.impl.PsiCachedValue.getValueWithLock(PsiCachedValue.java:60)
    at com.intellij.psi.impl.PsiCachedValueImpl.getValue(PsiCachedValueImpl.java:38)
    at com.intellij.util.CachedValuesManagerImpl.getCachedValue(CachedValuesManagerImpl.java:87)
    at com.intellij.psi.util.CachedValuesManager.getCachedValue(CachedValuesManager.java:139)
    at com.intellij.psi.util.CachedValuesManager.getCachedValue(CachedValuesManager.java:126)
    at com.intellij.psi.impl.source.ClassInnerStuffCache.getFields(ClassInnerStuffCache.java:41)
    at org.jetbrains.kotlin.asJava.classes.KtLightClassBase.getFields(KtLightClassBase.kt:36)
    at org.jetbrains.uast.UClass$DefaultImpls.getFields(UClass.kt:53)
    at org.jetbrains.uast.UClassTypeSpecific$DefaultImpls.getFields(UClass.kt)
    at org.jetbrains.uast.kotlin.AbstractKotlinUClass.getFields(KotlinUClass.kt:33)
    at org.jetbrains.uast.kotlin.KotlinUAnonymousClass.getFields(KotlinUClass.kt:221)
    at org.jetbrains.uast.kotlin.AbstractKotlinUClass$uastDeclarations$2.invoke(KotlinUClass.kt:38)
    at org.jetbrains.uast.kotlin.AbstractKotlinUClass$uastDeclarations$2.invoke(KotlinUClass.kt:33)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at org.jetbrains.uast.kotlin.AbstractKotlinUClass.getUastDeclarations(KotlinUClass.kt)
    at org.jetbrains.uast.UClass$DefaultImpls.accept(UClass.kt:69)
    at org.jetbrains.uast.UClassTypeSpecific$DefaultImpls.accept(UClass.kt)
    at org.jetbrains.uast.kotlin.AbstractKotlinUClass.accept(KotlinUClass.kt:33)
    at org.jetbrains.uast.UObjectLiteralExpression$DefaultImpls.accept(UObjectLiteralExpression.kt:56)
    at org.jetbrains.uast.kotlin.KotlinUObjectLiteralExpression.accept(KotlinUObjectLiteralExpression.kt:31)
    at org.jetbrains.uast.internal.ImplementationUtilsKt.acceptList(implementationUtils.kt:23)
    at org.jetbrains.uast.kotlin.KotlinUFunctionCallExpression.accept(KotlinUFunctionCallExpression.kt:135)
    at org.jetbrains.uast.UQualifiedReferenceExpression$DefaultImpls.accept(UQualifiedReferenceExpression.kt:48)
    at org.jetbrains.uast.kotlin.KotlinUQualifiedReferenceExpression.accept(KotlinUQualifiedReferenceExpression.kt:29)
    at org.jetbrains.uast.internal.ImplementationUtilsKt.acceptList(implementationUtils.kt:23)
    at org.jetbrains.uast.UBlockExpression$DefaultImpls.accept(UBlockExpression.kt:35)
    at org.jetbrains.uast.kotlin.KotlinUBlockExpression.accept(KotlinUBlockExpression.kt:24)
    at org.jetbrains.uast.ULambdaExpression$DefaultImpls.accept(ULambdaExpression.kt:47)
    at org.jetbrains.uast.kotlin.KotlinULambdaExpression.accept(KotlinULambdaExpression.kt:27)
    at org.jetbrains.uast.internal.ImplementationUtilsKt.acceptList(implementationUtils.kt:23)
    at org.jetbrains.uast.kotlin.KotlinUFunctionCallExpression.accept(KotlinUFunctionCallExpression.kt:135)
    at org.jetbrains.uast.internal.ImplementationUtilsKt.acceptList(implementationUtils.kt:23)
    at org.jetbrains.uast.UBlockExpression$DefaultImpls.accept(UBlockExpression.kt:35)
    at org.jetbrains.uast.kotlin.KotlinUBlockExpression$KotlinLazyUBlockExpression.accept(KotlinUBlockExpression.kt:30)
    at org.jetbrains.uast.UAnnotationMethod$DefaultImpls.accept(UMethod.kt:109)
    at org.jetbrains.uast.kotlin.declarations.KotlinUMethod.accept(KotlinUMethod.kt:32)
    at org.jetbrains.uast.internal.ImplementationUtilsKt.acceptList(implementationUtils.kt:23)
    at org.jetbrains.uast.UClass$DefaultImpls.accept(UClass.kt:69)
    at org.jetbrains.uast.UClassTypeSpecific$DefaultImpls.accept(UClass.kt)
    at org.jetbrains.uast.kotlin.AbstractKotlinUClass.accept(KotlinUClass.kt:33)
    at org.jetbrains.uast.internal.ImplementationUtilsKt.acceptList(implementationUtils.kt:23)
    at org.jetbrains.uast.UFile$DefaultImpls.accept(UFile.kt:91)
    at org.jetbrains.uast.kotlin.KotlinUFile.accept(KotlinUFile.kt:30)
    at com.android.tools.lint.client.api.UastGradleVisitor.visitBuildScript(UastGradleVisitor.kt:36)
    at com.android.tools.lint.client.api.LintDriver$checkBuildScripts$1.run(LintDriver.kt:1127)
    at com.android.tools.lint.client.api.LintClient.runReadAction(LintClient.kt:1510)
    at com.android.tools.lint.client.api.LintDriver$LintClientWrapper.runReadAction(LintDriver.kt:2115)
    at com.android.tools.lint.client.api.LintDriver.checkBuildScripts(LintDriver.kt:1111)
    at com.android.tools.lint.client.api.LintDriver.runFileDetectors(LintDriver.kt:1052)
    at com.android.tools.lint.client.api.LintDriver.checkProject(LintDriver.kt:850)
    at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.kt:378)
    at com.android.tools.lint.LintCliClient.run(LintCliClient.java:238)
    at com.android.tools.lint.gradle.LintGradleClient.run(LintGradleClient.java:230)
    at com.android.tools.lint.gradle.LintGradleExecution.runLint(LintGradleExecution.java:291)
    at com.android.tools.lint.gradle.LintGradleExecution.lintSingleVariant(LintGradleExecution.java:368)
    at com.android.tools.lint.gradle.LintGradleExecution.analyze(LintGradleExecution.java:91)
    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:498)
    at com.android.tools.lint.gradle.api.ReflectiveLintRunner.runLint(ReflectiveLintRunner.kt:38)
    at com.android.build.gradle.tasks.LintBaseTask.runLint(LintBaseTask.java:88)
    at com.android.build.gradle.tasks.LintPerVariantTask.lint(LintPerVariantTask.java:41)
    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:498)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:801)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:768)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipCachedTaskExecuter.execute(SkipCachedTaskExecuter.java:105)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ResolveBuildCacheKeyExecuter.execute(ResolveBuildCacheKeyExecuter.java:79)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
    at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.run(EventFiringTaskExecuter.java:51)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
    at org.gradle.execution.taskgraph.LocalTaskInfoExecutor.execute(LocalTaskInfoExecutor.java:42)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:277)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareWorkItemExecutor.execute(DefaultTaskExecutionGraph.java:262)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:135)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:130)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.execute(DefaultTaskPlanExecutor.java:200)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.executeWithWork(DefaultTaskPlanExecutor.java:191)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$ExecutorWorker.run(DefaultTaskPlanExecutor.java:130)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:748)

2 个答案:

答案 0 :(得分:1)

为了修复棉绒任务,我必须删除android块内的以下代码:

android {
    applicationVariants.all(object : Action<ApplicationVariant> {
        override fun execute(variant: ApplicationVariant) {
        }
    })
}

我仍然不确定为什么这段代码会破坏皮棉,但是我发布了一个回购,其中包含有关如何复制的示例。

https://github.com/erchenger/Lint-Bug-Migrating-to-KTS-Gradle-Scripts

公开的Google问题是:https://issuetracker.google.com/issues/122301469

答案 1 :(得分:0)

正如您在上一个答案中已经提到的那样,问题是gradle文件中的applicationVariants.all语句:

android {
    applicationVariants.all(object : Action<ApplicationVariant> {
        override fun execute(variant: ApplicationVariant) {
            // whatever you do here
        }
    })
}

这在groovy脚本gradle文件中工作正常,但应如何使用kotlin脚本文件将其调用方式更改为configureEach。因此,当您需要动态配置applicationVariant时,必须使用如下代码段:

android {
    applicationVariants.configureEach {
        // this = ApplicationVariant
        // whatever you do here
    }
}