使用带有Android Studio 3.0 beta7的房间时,Kotlin注释处理器会出现编译时错误

时间:2017-10-06 08:21:25

标签: android android-studio kotlin android-studio-3.0 kapt

我正在使用Android Studio 3.0 Beta 7编译Android项目,使用Kotlin 1.4-2和Room Persistence Library 1.0.0-beta1。

这是我的Gradle文件的一部分,我添加了房间依赖:

implementation "android.arch.persistence.room:runtime:1.0.0-beta1"
kapt "android.arch.persistence.room:compiler:1.0.0-beta1"

编译时遇到以下错误:

  

警告:警告:支持的源版本' RELEASE_7'来自注释   处理器' android.arch.persistence.room.RoomProcessor'少于   -source' 1.8'

在编译选项中添加stacktrace / debug标志后,这就是我得到的错误:

  

错误:org.jetbrains.kotlin.kapt3.diagnostic.KaptError:错误时   注释处理

     

10:08:03.727 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE:构建因异常而失败。   10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]   10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] *出了什么问题:   10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]任务':app:kaptDebugKotlin'执行失败。   10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]>内部编译器错误。有关详细信息,请参阅日志   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] *异常是:   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException:任务':app:kaptDebugKotlin'执行失败。   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)   10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker $ 1.run(DefaultTaskGraphExecuter.java:248)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.access $ 200(DefaultTaskPlanExecutor.java:80)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:105)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:99)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ExecutorPolicy $ CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ManagedExecutorImpl $ 1.run(ManagedExecutorImpl.java:46)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ThreadFactoryImpl $ ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)   10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]引起:org.gradle.api.GradleException:内部编译器错误。有关详细信息,请参阅日志   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:9)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.jetbrains.kotlin.gradle.internal.KaptTask.compile(KaptTask.kt:71)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore $ StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore $ StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore $ StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:731)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:705)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter $ 1.run(ExecuteActionsTaskExecuter.java:122)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)   10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)   10:08:03.730 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)   10:08:03.730 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)   10:08:03.730 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] ... 27更多   10:08:03.730 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]   10:08:03.730 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]   10:08:03.730 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] *在https://help.gradle.org获取更多帮助   10:08:03.730 [错误] [org.gradle.internal.buildevents.BuildResultLogger]   10:08:03.730 [错误] [org.gradle.internal.buildevents.BuildResultLogger]在8s内建立失败

清洁/重建没有帮助。可能导致此错误的原因是什么?临时解决方案似乎正在取代" kapt"使用标准" annotationProcessor",重建然后用" kapt"再次构建。但是在项目进一步改变后,错误再次出现。

[编辑]

我的Gradle文件(应用模块):

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.mydomain.myapp"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

androidExtensions {
    experimental = true
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

    // Anko Commons
    implementation "org.jetbrains.anko:anko-commons:$anko_version"

    // Timber logging
    implementation "com.jakewharton.timber:timber:$timber_version"

    // Architecture components - Lifecycle
    implementation "android.arch.lifecycle:extensions:$arch_version"
    kapt "android.arch.lifecycle:compiler:$arch_version"

    // Architecture components - Room ORM
    implementation "android.arch.persistence.room:runtime:$arch_version"
    kapt "android.arch.persistence.room:compiler:$arch_version"

    // Retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

    // Picasso
    implementation "com.squareup.picasso:picasso:$picasso_version"
}

Gradle(项目模块):

buildscript {
    ext.kotlin_version = '1.1.4-2'
    ext.anko_version = '0.10.1'
    ext.timber_version = '4.5.1'
    ext.retrofit_version = '2.3.0'
    ext.picasso_version = '2.5.2'
    ext.constraint_layout_version = '1.0.2'
    ext.support_library_version = '26.1.0'
    ext.arch_version = '1.0.0-beta1'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta7'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

3 个答案:

答案 0 :(得分:4)

我也使用kapt插件和房间,并有类似的错误。在我的情况下,我通过将此行apply plugin: 'kotlin-kapt'app build.gradle移动到top build.gradle块之外的buildscript{}来解决它,然后错误就消失了。 I found it here

答案 1 :(得分:1)

而不是依赖版本1.0.0-beta1使用1.0.0-beta2并尝试编译。

答案 2 :(得分:0)

这是Android Studio 3.0 beta7的一些问题,在更新到3.0-RC1后问题不再发生。