错误:任务':app:compileDebugKotlin'的执行失败。>编译错误。请参阅日志以获取更多详细信息


154
Error:Execution failed for task ':app:compileDebugKotlin'. > Compilation error. See log for more details

build:gradle(模块:app)

buildscript {
    repositories {
        maven {
            url 'https://jitpack.io'
            url 'https://maven.fabric.io/public'
        }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android-extensions'


repositories {
    maven { url 'https://maven.fabric.io/public' }
    mavenCentral()
}


android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    useLibrary 'org.apache.http.legacy'



    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

    defaultConfig {
        applicationId "uxx.xx.xxe"
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 17
        versionName "0.1.14"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            ext.enableCrashlytics = false
            debuggable true
            minifyEnabled true
            shrinkResources true

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
            assets.srcDirs = ['src/main/assets', 'src/main/assets/']
            res.srcDirs = ['src/main/res', 'src/main/assets/fonts']
        }
    }

    dexOptions {
        jumboMode true
        javaMaxHeapSize "4g"

    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/ECLIPSE_.SF'
        exclude 'META-INF/ECLIPSE_.RSA'
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    compile "com.android.support:cardview-v7:${rootProject.supportLibraryVersion}"
       compile "com.google.android.gms:play-services-ads:${rootProject.googlePlayServicesVersion}"
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    compile 'org.igniterealtime.smack:smack-android-extensions:4.1.9'
    compile 'org.igniterealtime.smack:smack-tcp:4.1.9'
    compile 'org.igniterealtime.smack:smack-experimental:4.1.9'
    testCompile 'junit:junit:4.12'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.getkeepsafe.dexcount'

build:gradle(项目)

//顶层构建文件,您可以在其中添加所有子项目/模块共有的配置选项。

buildscript {
    ext.kotlin_version = '1.1.2-2'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        classpath 'com.google.gms:google-services:3.0.0'
        //visualize the method count
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

ext.googlePlayServicesVersion = '10.2.0'
ext.supportLibraryVersion = '25.3.1'

task clean(type: Delete) {
    delete rootProject.buildDir
}

解决方案尝试:

  1. 无效的缓存/重启
  2. 构建->清洁项目
  3. 更新kotlin插件,使用kotlin的最新版本,Google API。

编辑

./gradlew build --stacktrace > logs.txt 2>logErrors.txt

logErrors.txt

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugKotlin'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
    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.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
    at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
    at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:8)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.processCompilerExitCode(Tasks.kt:286)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:260)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:160)
    at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:141)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:163)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
    ... 70 more

您还可以发布日志中的任何内容吗?
zsmb13

1
嘿,对不起。实际上,我不知道该在哪里寻找日志。您还能帮我吗@ zsmb13
Ankur_009

@ zsmb13我已在消息部分下查找,但没有可用的日志
Ankur_009

@ zsmb13我添加了日志
Ankur_009

您可能应该在Kotlin Bugtracker中提出问题
ChristianBrüggemann17年

Answers:


211

经过简单的代码重构尝试后,出现了此类错误。它没有发生,也没有连接任何库之后,gradle的任何更改都没有。看起来我的代码中有错误,但是编译器找不到问题。这就是为什么我仔细检查所做的所有更改并发现我以某种方式更改了接口中的方法签名,但未在实现它的类中对其进行更改的原因。我在一天中两次遇到此错误,因此决定分享我的经验。我希望这是一个临时的编译器错误。

解决方案1可能的解决方法是转到“文件”->“设置”->“编译器”->,然后在命令行选项中添加“ --stacktrace --debug”。阅读日志并尝试找到问题所在的答案。

在新的Android Studio 3.1。+中,您可以通过按“构建”选项卡上的“切换视图”来启用/禁用控制台日志详细信息。在那里您可以找到详细信息。请注意,两种模式都可用于调查问题的原因。参见:https : //stackoverflow.com/a/49717363/

在此处输入图片说明

解决方案2单击Gradle(在右侧栏上),然后在“ :app选择” 下assembleDebug(或assembleYourFlavor如果使用调味料)。错误将显示在“运行”选项卡中。请参阅:https//stackoverflow.com/a/51022296

解决方案3不得已。在android studio中,尝试分析->检查代码->整个项目。等待检查结束,然后更正“常规”部分中的错误以及其他部分中可能的错误。

注意 kapt3可能是此类错误的来源。我删除apply plugin: 'kotlin-kapt'并添加kapt { generateStubs = true }android {}build.gradle部分。kapt生成器的先前版本似乎没有错误。更新。看起来像是kapt的错误在kotlin 1.2。+上已经消失了。)


2
@newbie我希望有一天我们将获得有关此类问题的修复程序更新。
Yazon2006年

1
好吧,上次更新中的此解决方案对我来说有些工作。删除kotlin-kapt并添加kapt {generetaStubs = true}
无限循环

3
不推荐使用原始(旧)kapt,并将在Kotlin 1.2之后将其完全删除。如果您遇到任何问题apply plugin: 'kotlin-kapt',请向kotl.in/issue提出问题。
yanex

3
@IgorGanapolsky在android studio中尝试分析->检查代码->整个项目。等待检查结束,然后更正“常规”部分中的错误。
Yazon2006年

1
我正在使用Android Studio 3.3,而Kotlin版本1.3.20解决方案3帮了我大忙。非常感谢。
hunter09h

103

如果您使用的是AS 3.1,则新的图形控制台对查找问题根源不是很有帮助。

您需要单击切换视图,然后以文本格式查看日志,以查看错误以及是否需要 Run with --stacktrace

在此处输入图片说明


4
谢谢!!经过数小时的调试,我不得不这样做。我想添加到您的答案中的一件事是,该错误可能是在包含“编译错误。请参阅日志以获取更多详细信息”消息的那一行之上。
伊万·埃斯帕萨(IvánEsparza),

谢谢!看到文本错误更为明确。经过数小时的调试,我发现了正确的错误。对我来说,这是由于viewModel的@inject所致,我也忘记将注释放在viewModel构造函数上
Badr

有趣的是,这是捕获与Dagger相关的错误的唯一方法。荒谬!
egorikem '18

非常感谢您的回答。我发现忘记了在LoggingInterceptor中导入Log。
Raj Suvariya '18

4
如果无法将编译错误传达给开发人员,则IDE与IDE一样失败。认真地Google:周末工作直到解决。
尼尔佐

99

我有误导性的错误消息,类似于问题中发布的错误消息:

编译错误。请参阅日志以获取更多详细信息

和:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugKotlin'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    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.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    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:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.gradle.api.GradleException: Compilation error. See log for more details
    at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:16)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.processCompilerExitCode(Tasks.kt:429)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:390)
    at org.jetbrains.kotlin.gradle.tasks.KotlinCompile.callCompiler$kotlin_gradle_plugin(Tasks.kt:274)
    at org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile.execute(Tasks.kt:233)
    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.IncrementalTaskAction.doExecute(IncrementalTaskAction.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.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:121)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 32 more

解:

我解决了

  1. 单击Gradle(在右侧栏上)->
  2. 然后在 :app
  3. 然后选择assembleDebug(或assembleYourFlavor使用调味料)

在图片中:

1&2:

s1

3:

s2

错误将显示在“运行:”选项卡中。


5
谢谢。使用此方法发现了问题。需要注意的一件事是,当向后滚动日志时,首先显示的并没有太大帮助的原始gradle错误,然后继续滚动,您将发现原始错误。可以通过导致问题的源文件的蓝色链接轻松识别。
马修·考利

4
如果列出,我看不到“ assembleDebug”
user7856586 '19

1
项目根目录下的“ ./gradlew assembleDebug”将完成这项工作
英特尔

我也是@ user7856586,也没有找到assembleDebug
Vikas Pandey

2
“:app / Tasks / other / assembleDebug”是当前路径
-Farwa

14

在这种情况下,gradle console它会详细显示问题所在的确切位置,从而导致此编译错误。

就我而言,我Butterknife在一个auto-converted班级中kotlin使用过,而该班级使用的是android studio的实用程序

Log in Gradle Console

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
:app:buildInfoDebugLoader
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:checkDebugManifest UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:processDebugGoogleServices
Parsing json file: /Users/Downloads/myproject/app/google-services.json
:app:mergeDebugResources UP-TO-DATE
:app:createDebugCompatibleScreenManifests UP-TO-DATE
:app:processDebugManifest
:app:splitsDiscoveryTaskDebug UP-TO-DATE
:app:processDebugResources
:app:kaptGenerateStubsDebugKotlin
Using kotlin incremental compilation
:app:kaptDebugKotlin
e: /Users/Downloads/myproject/app/build/tmp/kapt3/stubs/debug/com/myproject/util/ConfirmationDialog.java:10: error: @BindView fields must not be private or static. (com.myproject.util.ConfirmationDialog.imgConfirmationLogo)
e: 

e:     private android.widget.ImageView imgConfirmationLogo;
e:                                      ^
e: /Users/Downloads/myproject/app/build/tmp/kapt3/stubs/debug/com/myproject/util/ConfirmationDialog.java:13: error: @BindView fields must not be private or static. (com.myproject.util.ConfirmationDialog.txtConfirmationDialogTitle)
e: 

e:     private android.widget.TextView txtConfirmationDialogTitle;
e:                                     ^
e: /Users/Downloads/myproject/app/build/tmp/kapt3/stubs/debug/com/myproject/util/ConfirmationDialog.java:16: error: @BindView fields must not be private or static. (com.myproject.util.ConfirmationDialog.txtConfirmationDialogMessage)
e: 

e:     private android.widget.TextView txtConfirmationDialogMessage;
e:                                     ^
e: /Users/Downloads/myproject/app/build/tmp/kapt3/stubs/debug/com/myproject/util/ConfirmationDialog.java:19: error: @BindView fields must not be private or static. (com.myproject.util.ConfirmationDialog.txtViewPositive)
e: 

e:     private android.widget.TextView txtViewPositive;
e:                                     ^
e: /Users/Downloads/myproject/app/build/tmp/kapt3/stubs/debug/com/myproject/util/ConfirmationDialog.java:22: error: @BindView fields must not be private or static. (com.pokkt.myproject.ConfirmationDialog.txtViewNegative)
e: 

e:     private android.widget.TextView txtViewNegative;
e:                                     ^
e: /Users/Downloads/myproject/app/build/tmp/kapt3/stubs/debug/com/myproject/util/ExitDialog.java:10: error: @BindView fields must not be private or static. (com.myproject.util.ExitDialog.txtViewPositive)
e: 

e:     private android.widget.TextView txtViewPositive;
e:                                     ^
e: /Users/Downloads/myproject/app/build/tmp/kapt3/stubs/debug/com/myproject/util/ExitDialog.java:13: error: @BindView fields must not be private or static. (com.myproject.util.ExitDialog.txtViewNegative)
e: 

e:     private android.widget.TextView txtViewNegative;
e:                                     ^
e: java.lang.IllegalStateException: failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing
    at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:57)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:144)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:167)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
    at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:182)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.execCompiler(CompileServiceImpl.kt:397)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execCompiler(CompileServiceImpl.kt:99)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:365)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:99)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2$$special$$inlined$withValidClientOrSessionProxy$lambda$1.invoke(CompileServiceImpl.kt:798)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2$$special$$inlined$withValidClientOrSessionProxy$lambda$1.invoke(CompileServiceImpl.kt:99)
    at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:825)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$checkedCompile(CompileServiceImpl.kt:99)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2.invoke(CompileServiceImpl.kt:797)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2.invoke(CompileServiceImpl.kt:99)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive(CompileServiceImpl.kt:1004)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive$default(CompileServiceImpl.kt:865)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:791)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$doCompile(CompileServiceImpl.kt:99)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1.invoke(CompileServiceImpl.kt:364)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1.invoke(CompileServiceImpl.kt:99)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive(CompileServiceImpl.kt:1004)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive$default(CompileServiceImpl.kt:865)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:336)
    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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    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)
Caused by: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing
    at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:90)
    at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:42)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:205)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:166)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:82)
    at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:89)
    at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:99)
    at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:76)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.analyze(KotlinToJVMBytecodeCompiler.kt:365)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:105)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:354)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:139)
    ... 40 more


 FAILED
:app:buildInfoGeneratorDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> Internal compiler error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED in 32s

16 actionable tasks: 7 executed, 9 up-to-date

在我的日志中,它清楚地表明了问题与黄油刀声明有关。因此,我调查了此问题并能够解决。


在我看来,最好使用kotlin扩展而不是黄油刀。但是,感谢您分享您的经验。对许多人来说可能是有帮助的。
Yazon2006年

@ Yazon2006 kotlin现在支持许多android框架,这就是为什么我尝试尝试一下kotlinlang.org/docs/tutorials/android-frameworks.html
DeltaCap019 '17

1
你是对的!但是,如果我们确切地讨论通过黄油刀中的@BindView进行视图初始化,我发现kotlin扩展提供了更简单的方法来获取代码中的视图实例。看看吧,您一定会喜欢的)kotlinlang.org/docs/tutorials/android-plugin.html
Yazon2006年

1
@ Yazon2006感谢您的链接,它比容易得多butterknife
DeltaCap019

10

在Mac上:

转到Android Studio>“偏好设置”>“构建,执行,部署”>“编译器”

在Windows上:

转到文件>设置>>生成,执行,部署>编译器

现在,在“命令行选项”字段中,添加以下三个标志:

--stacktrace --info --scan

如下图所示

在此处输入图片说明

现在,从Android Studio的底部打开Build窗口 在此处输入图片说明

然后,在“构建”窗口的左侧有一个按钮:

在此处输入图片说明

按下此按钮,您将看到详细的日志,其中包含阻止项目编译的确切代码


7

我有一个类似的问题。问题是我在视图的属性中错误地写入了模型的属性:

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@{ferm.coin.value}"/> 

这部分是错误的:

@{ferm.coin.value}

当我编写正确的属性时,该错误已解决。


6

存在Kotlin编译错误时,将显示此错误。

运行以下命令以查找哪里存在Kotlin编译错误,

gradlew clean assembleDebug (for Windows)
./gradlew clean assembleDebug (for Linux and Mac)

它会告诉您Kotlin编译错误在哪一行的确切位置。


6

我将项目更改为使用Androidx,因此我使用了迁移工具,但是某些文件(许多文件)没有自动更改。我打开了每个文件(活动,枚举,片段),发现了很多错误。我纠正了它们,但编译器仍然显示出我无法理解的错误。寻找解决方案后,我发现有人回答:

转到分析>>检查代码

在此处输入图片说明

整个项目:

在此处输入图片说明

花了一些时间,然后向我显示了以下结果:

在此处输入图片说明

当我纠正了我认为很重要的错误时,我正在运行构建,直到其余错误不再影响构建。

我的Android Studio详细信息

在此处输入图片说明


4

我找到了解决此问题的一种方法。

请按照以下步骤操作:

  1. 转到“文件”->“设置”->“编译器”->“添加到--stacktrace --debug”,然后单击“确定”。
  2. 重建一个项目。
  3. 运行一个项目。

3

我也遇到了同样的问题,我通过检查“构建”选项卡并切换到文本模式来解决该问题。检查控制台,它将显示我的问题是删除可绘制对象而不删除用法,并删除类而不删除用法也是 文本模式按钮


2

就我而言,我不小心将其更改 version="1.0"xml version="1.0"XML文件。

我只需要改回来。

如果您遇到相同的问题,并且上述解决方案对您不起作用。打开Gradle Console并滚动以Run with --debug option单击它,它将为您显示有关错误的更多有用信息。

一些注意事项:

在更改XML之后,不会直接显示此错误,而仅在更改某些Java代码后才会显示此错误。我认为这与即时运行和积累现金有关。


2

我想在上面添加我的解决方案,也许可以帮助某人。当我创建一个field上通过模型Room和不产生getter/setterfield。结果项目没有编译,也没有明显的错误。


2

我遇到了同样的问题,终于找到了原因。就我而言,这是一个写得不好的Java方法:

@FormUrlEncoded
@POST("register-user/")
Call<RegisterUserApiResponse> registerUser(
        @Field("email") String email,
        @Field("password") String password,            
        @Field("date") String birthDate,
);

请注意“日期”字段后的非法逗号。由于某种原因,编译器无法揭示此确切的错误,并且附带了一些':app:compileDebugKotlin'. > Compilation error东西。




2

我无缘无故遇到类似的问题,我认为这是由IDE(android studio)引起的。我已经尝试了上述所有解决方案,但是没有用。最后,在我自己的情况下,我通过以下操作解决了此问题:-关闭当前项目,并将其从android studio中的项目列表中删除Open an existing Android Studio project,然后通过重新打开它,然后它可以工作。希望我的经验对您有所帮助。


2

在我的情况下::我曾经kotlin extensions用来访问和绑定视图,我最近将a移到了view另一个屏幕,却忘记了从导致该错误的先前片段中删除其引用。

kotlin synthetic extensions编译时不安全。我真的很喜欢这个,但是显然在大型项目中,如果再次发生这种情况,我肯定会心脏病发作。


1

我有同样的问题。要解决此问题,只需打开您所做的所有文件(最近的工作文件),然后检查是否忘记删除一些应删除的文件。

在我的情况下,问题出在我在一个文件中使用的未引用代码,并且该代码存在于该文件中,该代码不应存在于该文件中,因为我使用的是我从项目中删除的接口,但是我忘记从我的文件之一中删除)。


1

就我而言,我试图升级play_servicesfirebase版本15.0。回到11.4.2修正我的问题...


1

我的情况:

旧的Kotlin数据类:

data class AddHotelParams(val destination: Place?, val checkInDate: LocalDate,
                      val checkOutDate: LocalDate?): JsonObject

新的Kotlin数据类:

data class AddHotelParams(val destination: Place?, val checkInDate: LocalDate,
                      val checkOutDate: LocalDate?, val roundTrip: Boolean): JsonObject

问题是我忘记在代码的某些部分中更改对象初始化。我收到一个通用的“ compileInternalDebugKotlin”错误,而不是被告知需要更改初始化的位置。

将初始化更改为代码的所有部分可以解决该错误。


1

就我而言,我忘记将返回类型添加到我从RoomDatabase继承的类中的函数中:

abstract class LocalDb : RoomDatabase() {
    abstract fun progressDao(): ProgressDao
}

ProgressDao返回类型失踪。


0

最近的另一种可能的解决方案是将gradle版本更改为:

classpath 'com.android.tools.build:gradle:3.0.0-rc2'

和更新构建工具


0

我遇到了同样的问题,终于找到了解决方案。

在命令行选项(文件->设置->编译器)中添加“ --stacktrace --debug ”,然后运行它。这将在您的代码中显示问题(不需要的代码)。


0

就我而言,错误是由该行引起的

@BindColor(R.color.colorAccent)var mColor:整数?= 0

解决者

@JvmField @BindColor(android.R.color.white)@ColorInt内部变量mColor:Int = 0

GradleConsole中的错误

:app:kaptDebugKotlin e:\ app \ build \ tmp \ kapt3 \ stubs \ debug \ MainFragment.java:23:错误:@BindColor字段类型必须为'int'或'ColorStateList'。(com.sample.MainFragment.mColor)e:

e:私有java.lang.Integer mColor;


0

我很惊讶地发现,当我关闭一堂课时,产生了这个模糊的错误。将其更改为开放类可以解决此问题。

before:

 class DefaultSubscriber<T> : Observer<T> {//...
}

after:

open class DefaultSubscriber<T> : Observer<T> {//...
}

0

就我而言,更新com.android.tools.build:gradle到最新版本并以Gradle的在线模式重建项目解决了该问题。


0

下面的变化对我有用

我更改了位于gradle-wrapper.properties中的分发URL

distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }

kotlin版本1.2.71


0

在我的情况下,它是DAO类的房间持久性函数中未使用的参数


0

gradle assembleDebug --scan在Android Studio Terminal中运行,以我为例,我删除了XML中的一个元素,却忘记了将其从代码中删除,但是编译器无法编译并显示Error:Execution failed for task ':app:compileDebugKotlin'. > Compilation error. See log for more details给我。

在此处输入图片说明

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.