使用带有Android Studio 3.0 beta7的Room时,Kotlin注释处理器会出现编译时错误
作者:互联网
我正在使用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"
在编译时我遇到以下错误:
Warning:warning: Supported source version ‘RELEASE_7’ from annotation
processor ‘android.arch.persistence.room.RoomProcessor’ less than
-source ‘1.8’
在为编译选项添加stacktrace / debug标志之后,这是我得到的错误:
Error:org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while
annotation processing10:08:03.727 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:08:03.727 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
10:08:03.727 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:08:03.727 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
10:08:03.727 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ‘:app:kaptDebugKotlin’.
10:08:03.727 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Internal compiler error. See log for more details
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Exception is:
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:app:kaptDebugKotlin’.
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
10:08:03.729 [ERROR] [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] Caused by: org.gradle.api.GradleException: Internal compiler error. See log for more details
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:9)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.jetbrains.kotlin.gradle.internal.KaptTask.compile(KaptTask.kt:71)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:731)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:705)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
10:08:03.730 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
10:08:03.730 [ERROR] [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 more
10:08:03.730 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:08:03.730 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
10:08:03.730 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Get more help at 07001
10:08:03.730 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger]
10:08:03.730 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 8s
清洁/重建没有帮助.可能导致此错误的原因是什么?临时解决方案似乎是用标准的“annotationProcessor”替换“kapt”,重建然后再用“kapt”构建.但是在项目进一步改变之后,错误再次出现.
[编辑]
我的Gradle文件(app模块):
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
}
解决方法:
我也在使用kapt插件和房间,并且有类似的错误.在我的例子中,我通过将这行应用插件:’kotlin-kapt’从应用build.gradle移动到build build {}块之外的top build.gradle来解决它,然后错误就消失了.
I found it here
标签:android-studio-3-0,android,android-studio,kotlin,kapt 来源: https://codeday.me/bug/20190828/1750140.html