建设失败Kotlin kapt和房间

当我尝试使用Kotlin的架构组件时,我得到一个奇怪的编译器错误。

Gradle输出:

Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar] Configuration on demand is an incubating feature. Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead. Configuration 'androidTestCompile' in project ':app' is deprecated. Use 'androidTestImplementation' instead. Configuration 'testCompile' in project ':app' is deprecated. Use 'testImplementation' instead. 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin :app:preBuild UP-TO-DATE :app:preDebugBuild :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:mergeDebugResources UP-TO-DATE :app:createDebugCompatibleScreenManifests UP-TO-DATE :app:processDebugManifest :app:splitsDiscoveryTaskDebug UP-TO-DATE :app:processDebugResources :app:generateDebugSources :app:preDebugAndroidTestBuild :app:compileDebugAndroidTestAidl UP-TO-DATE :app:processDebugAndroidTestManifest :app:compileDebugAndroidTestRenderscript UP-TO-DATE :app:generateDebugAndroidTestBuildConfig UP-TO-DATE :app:generateDebugAndroidTestResValues UP-TO-DATE :app:generateDebugAndroidTestResources UP-TO-DATE :app:mergeDebugAndroidTestResources UP-TO-DATE :app:splitsDiscoveryTaskDebugAndroidTest UP-TO-DATE :app:processDebugAndroidTestResources UP-TO-DATE :app:generateDebugAndroidTestSources UP-TO-DATE :app:mockableAndroidJar UP-TO-DATE BUILD SUCCESSFUL in 1s 21 actionable tasks: 5 executed, 16 up-to-date Executing tasks: [clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar] Configuration on demand is an incubating feature. Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead. Configuration 'androidTestCompile' in project ':app' is deprecated. Use 'androidTestImplementation' instead. Configuration 'testCompile' in project ':app' is deprecated. Use 'testImplementation' instead. 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin :clean :app:clean :app:preBuild UP-TO-DATE :app:preDebugBuild :app:compileDebugAidl :app:compileDebugRenderscript :app:checkDebugManifest :app:generateDebugBuildConfig :app:generateDebugResValues :app:generateDebugResources :app:mergeDebugResources :app:createDebugCompatibleScreenManifests :app:processDebugManifest :app:splitsDiscoveryTaskDebug :app:processDebugResources :app:generateDebugSources :app:preDebugAndroidTestBuild :app:compileDebugAndroidTestAidl :app:processDebugAndroidTestManifest :app:compileDebugAndroidTestRenderscript :app:generateDebugAndroidTestBuildConfig :app:generateDebugAndroidTestResValues :app:generateDebugAndroidTestResources :app:mergeDebugAndroidTestResources :app:splitsDiscoveryTaskDebugAndroidTest :app:processDebugAndroidTestResources :app:generateDebugAndroidTestSources :app:mockableAndroidJar BUILD SUCCESSFUL in 2s 23 actionable tasks: 23 executed Executing tasks: [:app:assembleDebug] Configuration on demand is an incubating feature. Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead. Configuration 'androidTestCompile' in project ':app' is deprecated. Use 'androidTestImplementation' instead. Configuration 'testCompile' in project ':app' is deprecated. Use 'testImplementation' instead. 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin 'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin :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: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 w: warning: Supported source version 'RELEASE_7' from annotation processor 'android.arch.persistence.room.RoomProcessor' less than -source '1.8' w: w: /Users/maxgierlachowski/Projects/jooy/app/build/tmp/kapt3/stubs/debug/com/jooyapp/jooy/Persistence/Entities/Message.java:17: warning: Primary key constraint on chatId is ignored when being merged into com.jooyapp.jooy.Persistence.Entities.Message w: w: private com.jooyapp.jooy.Persistence.Entities.Chat chat; w: ^ w: /Users/maxgierlachowski/Projects/jooy/app/build/tmp/kapt3/stubs/debug/com/jooyapp/jooy/Persistence/Entities/Message.java:20: warning: Primary key constraint on userId is ignored when being merged into com.jooyapp.jooy.Persistence.Entities.Message w: w: private com.jooyapp.jooy.Persistence.Entities.User user; w: ^ e: /Users/maxgierlachowski/Projects/jooy/app/build/tmp/kapt3/stubs/debug/com/jooyapp/jooy/Persistence/DatabaseAccessObjects/ChatDataAccessObject.java:19: error: no viable alternative at input 'chat_id' e: e: public abstract com.jooyapp.jooy.Persistence.Entities.Chat getChat(@org.jetbrains.annotations.NotNull() e: ^ e: /Users/maxgierlachowski/Projects/jooy/app/build/tmp/kapt3/stubs/debug/com/jooyapp/jooy/Persistence/DatabaseAccessObjects/UserDataAccessObject.java:9: error: no viable alternative at input 'user_id' e: e: public abstract com.jooyapp.jooy.Persistence.Entities.User getUser(@org.jetbrains.annotations.NotNull() e: ^ w: warning: Supported source version 'RELEASE_7' from annotation processor 'android.arch.lifecycle.LifecycleProcessor' less than -source '1.8' w: 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 :app:kaptDebugKotlin 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 3s 15 actionable tasks: 6 executed, 9 up-to-date 

Gradle-File:

 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.jooyapp.jooy" 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' } } } kapt { generateStubs = true } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" testCompile 'junit:junit:4.12' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile "android.arch.persistence.room:runtime:$lifecycle_version" kapt "android.arch.persistence.room:compiler:$lifecycle_version" compile "android.arch.lifecycle:runtime:$lifecycle_version" compile "android.arch.lifecycle:extensions:$lifecycle_version" kapt "android.arch.lifecycle:compiler:$lifecycle_version" compile 'com.github.bumptech.glide:glide:4.0.0-RC0' kapt 'com.github.bumptech.glide:compiler:4.0.0-RC0' compile "com.android.support:support-compat:$support_library_version" compile "com.android.support:appcompat-v7:$support_library_version" compile "com.android.support:support-v4:$support_library_version" implementation "com.android.support:support-v4:$support_library_version" implementation "com.android.support:recyclerview-v7:$support_library_version" compile "com.google.dagger:dagger:2.11" kapt "com.google.dagger:dagger-compiler:2.11" } 

参数:

 ext.kotlin_version = '1.1.3-2' ext.lifecycle_version = '1.0.0-alpha5' ext.support_library_version = '26.0.0' 

我已经尝试改变lifecycle_version,但也没有帮助。 当在这一行使用annotationProcessor而不是kapt时:

 kapt "android.arch.persistence.room:compiler:$lifecycle_version" 

我得到另一个错误,因为从注释的代码没有创建,但另一个错误似乎已经消失。

ChatDAO:

 package com.jooyapp.jooy.Persistence.DatabaseAccessObjects import android.arch.lifecycle.LiveData import android.arch.persistence.room.Dao import android.arch.persistence.room.Insert import android.arch.persistence.room.Query import com.jooyapp.jooy.Persistence.Entities.Chat import com.jooyapp.jooy.Persistence.Entities.Message @Dao interface ChatDataAccessObject { @Query("SELECT * FROM Messages WHERE chat_id = :chatId") fun getMessagesForChat(chatId: String): LiveData<List> @Query("SELECT * FROM Messages WHERE chat_id = :chatId LIMIT :limit") fun getMessagesForChat(chatId: String, limit: Int): LiveData<List> @Query("SELECT * FROM Chats WEHRE chat_id = :chatId") fun getChat(chatId: String): Chat @Insert fun addChat(chat: Chat) } 

UserDAO:

 package com.jooyapp.jooy.Persistence.DatabaseAccessObjects import android.arch.persistence.room.Dao import android.arch.persistence.room.Insert import android.arch.persistence.room.Query import com.jooyapp.jooy.Persistence.Entities.Message import com.jooyapp.jooy.Persistence.Entities.User @Dao interface UserDataAccessObject { @Query("SELECT * FROM Users WEHRE user_id = :userId") fun getUser(userId: String): User @Insert fun addUser(user: User) } 

数据库:

 package com.jooyapp.jooy.Persistence import android.arch.persistence.room.Database import android.arch.persistence.room.RoomDatabase import com.jooyapp.jooy.Persistence.DatabaseAccessObjects.ChatDataAccessObject import com.jooyapp.jooy.Persistence.DatabaseAccessObjects.MessageDataAccessObject import com.jooyapp.jooy.Persistence.DatabaseAccessObjects.UserDataAccessObject import com.jooyapp.jooy.Persistence.Entities.Chat import com.jooyapp.jooy.Persistence.Entities.Message import com.jooyapp.jooy.Persistence.Entities.User @Database(entities = arrayOf(Message::class, User::class, Chat::class), version = 1, exportSchema = false) abstract class AppDatabase : RoomDatabase() { abstract fun chatDao(): ChatDataAccessObject abstract fun userDao(): UserDataAccessObject abstract fun messageDao(): MessageDataAccessObject } 

和用户代码:

 package com.jooyapp.jooy.Persistence.Entities import android.arch.persistence.room.Entity import android.arch.persistence.room.ColumnInfo import android.arch.persistence.room.PrimaryKey @Entity(tableName = "Users") data class User( @ColumnInfo(name = "user_id") @PrimaryKey var userId: String, @ColumnInfo(name = "name") var name: String, @ColumnInfo(name = "phone") var phone: String, @ColumnInfo(name = "avatar_url") var avatarUrl: String? ) 

在查询getChat有一个拼写错误,并且getUser使用的是WEHRE而不是WHERE