使用Android Studio 3.0 beta7版本时,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" 

编译时,我收到以下错误:

警告:警告:注释处理器“android.arch.persistence.room.RoomProcessor”支持的源版本“RELEASE_7”小于“源1.8”

添加stacktrace /调试标志来编译选项后,这是我得到的错误:

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

10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:08:03.727 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]失败:生成失败,出现exception。 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 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]>内部编译器错误。 10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:08:03.728 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Exception is: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]在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] 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 org.gradle.api.internal.tasks.execution [org.gradle.internal.buildevents.BuildExceptionReporter]。 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 [ERROR] [org.gradle.internal.buildevents。 BuildExceptionReporter]在org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)10:08:03.728 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.gradle.api .internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)10:08:03.728 [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter .execute(SkipOnlyIfTaskExecuter.java:54)10:08:03.728 [org.gradle.internal.buildevents.BuildExceptionReporter] 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 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.gradle.execution.taskgraph.DefaultTaskGraphExeter $ $ 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] 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.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] [org.gradle.internal.buildevents。 BuildExceptionReporter]在org.gradle.execution.taskgraph.DefaultTaskGraphExeterter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.gradle.execution.taskgraph .DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)10:08:03.729 [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java :124)10:08:03.729 [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.access $ 200(DefaultTaskPlanExecutor.java:80)10:08:03.729 [错误] [或 g.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 ]在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:99)10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]在org.gradle.execution.taskgraph .DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)10:08:03.729 [org.gradle.internal.buildevents.BuildExceptionReporter] 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 [ERROR] [org。 gradle.internal.buildevents.BuildExceptio org.gradle.internal.concurrent.ExecutorPolicy $ CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.internal.concurrent [nReporter] .ManagedExecutorImpl $ 1.run(ManagedExecutorImpl.java:46)10:08:03.729 org.gradle.internal.concurrent.ThreadFactoryImpl $ ManagedThreadRunnable.run [ThreadFactoryImpl.java: 55)10:08:03.729 [错误] [org.gradle.internal.buildevents.BuildExceptionReporter]引起:org.gradle.api.GradleException:内部编译器错误。 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 [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]在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 [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore $ StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)10:08:03.729 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReport 呃] 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 [org.gradle.internal.buildevents.BuildExceptionReporter] 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.ExecuteActionsTaskExeter $ 1.run(ExecuteActionsTaskExecuter.java:122) 10:08:03.729 [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]在org.gradle.internal.progress.DefaultB uildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)10:08:03.729 [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197) 10:08:03.729 [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更多10:08: 03.730 [错误] [org.gradle.internal .buildevents.BuildExceptionReporter] 10:08:03.730 [org.gradle.internal.buildevents.BuildExceptionReporter] 10:08:03.730 [ERROR] [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内失败

清理/重建不起作用。 什么可能导致这个错误? 临时解决方案似乎正在用标准的“annotationProcessor”替换“kapt”,然后重新构建,然后再用“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 Solutions collect form web for “使用Android Studio 3.0 beta7版本时,Kotlin注释处理器会导致编译时错误”

我也使用kapt插件和房间,并有类似的错误。 在我的情况下,我通过将这一行apply plugin: 'kotlin-kapt'app build.gradletop build.gradlebuildscript{}块之外来解决它,然后错误消失了。 我在这里find了

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

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

  • 如何在kotlin编程语言中使用如下所述的循环?
  • 当项目中的布局数量过大时,如何在android studio中管理/组织布局?
  • Android Studio 3无法建立kotlin片段
  • 在kotlin中生成方法或类注释
  • 在按钮上单击Admob插页式广告
  • 使用意向操作在Android Studio中创建Kotlin类
  • 用于将方法参数分配给Android Studio中的字段的Kotlin快捷方式
  • 各种问题@NonNull,@NotNull和@ParametersAreNonnullByDefault
  • 从字符串拆分空间不工作在Kotlin
  • Android Studio在layout.xml中显示错误
  • Kotlingenericstypes,types推断失败
  • Kotlin language will be the best programming language for Android.