Android lint 在基于 Kotlin 的 Gradle 脚本中失败



将我的build.gradle脚本迁移到build.gradle.kts后,我现在看到lint对我来说失败了。我创建了一个临时项目,我试图重现该问题无济于事(该项目完美运行 lint)。由于我对 lint 的运作方式不是非常了解,当我深入研究更多时,我想看看是否有其他人遇到过这个问题并知道可能发生了什么。

我怀疑是添加到

导致问题的构建过程中的东西,但在我查明问题之前,我希望得到一些反馈。

Kotlin 版本: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)

为了修复我的 lint 任务,我不得不删除 android 块内的以下代码:

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

我仍然不确定为什么这段代码会破坏 lint,但我发布了一个包含如何重现的示例的存储库。

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

开放的谷歌问题是:https://issuetracker.google.com/issues/122301469

正如您在之前的答案中已经提到的,问题是 gradle 文件中的applicationVariants.all语句:

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

这在时髦脚本 gradle 文件中工作正常,但应该如何调用它的方式随着 kotlin 脚本文件更改为configureEach .因此,当您需要动态配置应用程序变体时,您必须使用如下所示的代码段:

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

相关内容

  • 没有找到相关文章

最新更新