当我尝试在 Android Studio 中运行或构建应用程序时,我收到此警告。为什么我会得到这个?我需要注意这个警告吗?
The following options were not recognized by any processor: '[dagger.fastInit, kapt.kotlin.generated]'
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Kotlin和Room Persistance Library编写一个简单的应用程序.我按照Android Persistance codelab中的教程进行操作.
这是我AppDatabase
在Kotlin的课程:
@Database(entities = arrayOf(User::class), version = 1)
abstract class AppDatabase : RoomDatabase() {
abstract fun userModel(): UserDao
companion object {
private var INSTANCE: AppDatabase? = null
@JvmStatic fun getInMemoryDatabase(context: Context): AppDatabase {
if (INSTANCE == null) {
INSTANCE = Room.inMemoryDatabaseBuilder(context.applicationContext, AppDatabase::class.java).allowMainThreadQueries().build()
}
return INSTANCE!!
}
@JvmStatic fun destroyInstance() {
INSTANCE = null
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我试图运行应用程序时,它会立即崩溃.这是崩溃日志:
Caused by: java.lang.RuntimeException: cannot find implementation for com.ttp.kotlin.kotlinsample.room.AppDatabase. AppDatabase_Impl does not exist
at …
Run Code Online (Sandbox Code Playgroud) 我已经收到这样的错误好几天了,但我找不到解决方案。你能帮我么?
问题可能是由什么引起的?
错误 :
java.lang.IllegalAccessError: class org.jetbrains.kotlin.kapt3.base.KaptContext (in unnamed module @0x6acdb135) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x6acdb135
at org.jetbrains.kotlin.kapt3.base.KaptContext.<init>(KaptContext.kt:28)
at org.jetbrains.kotlin.kapt3.KaptContextForStubGeneration.<init>(KaptContextForStubGeneration.kt:40)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.contextForStubGeneration(Kapt3Extension.kt:287)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:171)
at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:102)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$invokeExtensionsOnAnalysisComplete(TopDownAnalyzerFacadeForJVM.kt:112)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:122)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:86)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:252)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:243)
at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:113)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:243)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:90)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:56)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:169)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:92)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:412)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:112)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:358)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:300)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl$rebuild(IncrementalCompilerRunner.kt:119)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:170)
at …
Run Code Online (Sandbox Code Playgroud) 未找到Gradle DSL方法:'kapt()'可能的原因:项目'jetpacklearn'可能正在使用不包含该方法的Android Gradle插件版本(例如,在1.1.0中添加了'testCompile')。将插件升级到版本3.4.0并同步项目
项目“ jetpacklearn”可能正在使用不包含该方法的Gradle版本。打开Gradle包装器文件
我的gradleVersion是'3.4.0',但无法处理,请问同样的问题
classpath "com.android.tools.build:gradle:$gradleVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
Run Code Online (Sandbox Code Playgroud) Error:Not sure how to convert a Cursor to this method's return type
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Run Code Online (Sandbox Code Playgroud)
使用Room
我收到此错误,我想找出导致它的方法.
我有多个DAO
s,总共有大约60个方法,并且在添加方法之后弹出了这个错误(从另一个完美工作的复制和粘贴,只是将字段更改为设置).
我可以发布整个类的DAO
s,但我想知道哪种方法失败了.我试着用Run with --stacktrace
,Run with --info
和--debug option
,但这些都不显示出任何有价值的信息.
我添加的方法是一个@Query
UPDATE
与Int
返回类型,如在建议的文档
UPDATE或DELETE查询可以返回void或int.如果是int,则该值是受此查询影响的行数.
编辑:我想补充一点,我尝试删除该方法,使DAO回到工作状态,但它仍然给我这个错误.
EDIT2:添加gradle控制台输出,因为在评论中不可读:
error: Not sure how to convert a Cursor to this method's return type
error: Not sure how to convert a Cursor to …
Run Code Online (Sandbox Code Playgroud) android dao kapt android-room android-architecture-components
任务“:app:kspDebugKotlin”执行失败。无法构建ksp
“compileDebugJavaWithJavac”任务(当前目标是 1.8)和“kspDebugKotlin”任务(当前目标是 17)jvm 目标兼容性应设置为相同的 Java 版本。
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
Run Code Online (Sandbox Code Playgroud) 有没有办法使用kapt作为androidtest范围?目前我正在从com.neenbedankt.gradle.plugins android-apt迁移到kapt - 这工作正常 - 但我不知道如何为androidTest范围做到这一点 - 所以替换:
apt "com.github.hotchemi:permissionsdispatcher-processor:$permissiondispatcher_version"
apt "com.google.dagger:dagger-compiler:$dagger_version"
Run Code Online (Sandbox Code Playgroud)
同
kapt "com.github.hotchemi:permissionsdispatcher-processor:$permissiondispatcher_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
Run Code Online (Sandbox Code Playgroud)
工作正常 - 但我发现无法迁移:
androidTestApt "com.google.dagger:dagger-compiler:$dagger_version"
Run Code Online (Sandbox Code Playgroud) 我试图在我的项目中使用Kotlin Annotation Processing Tool(kapt)包含Dagger Android处理器(此处记录).
我在我的build.gradle
文件中包含了正确的依赖项:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
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'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}) …
Run Code Online (Sandbox Code Playgroud) kapt
当我尝试使用to迁移 Android 项目时收到错误消息KSP
。
错误信息
Unable to find method ''void org.jetbrains.kotlin.gradle.tasks.KotlinCompile.<init>(org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions)''
'void org.jetbrains.kotlin.gradle.tasks.KotlinCompile.<init>(org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions)'
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project …
Run Code Online (Sandbox Code Playgroud) 我们正在尝试缩短多模块 Android 应用程序的构建时间,并且已经达到了尝试启用增量 KAPT 注释处理编译的程度。
gradle.properties:
org.gradle.daemon=true
org.gradle.caching=true
org.gradle.parallel=true
kapt.incremental.apt=true
kapt.use.worker.api=true
kapt.include.compile.classpath=false
android.databinding.incremental=true
Run Code Online (Sandbox Code Playgroud)
build.gradle(在每个使用 Room 的模块中):
kapt {
arguments {
arg("room.incremental", "true")
}
}
Run Code Online (Sandbox Code Playgroud)
但是,在尝试使用gradlew assemble -scan
命令对构建时间进行基准测试时,Gradle 会引发以下错误:
warning: Current JDK version 1.8.0_201-b09 has a bug (https://bugs.openjdk.java.net/browse/JDK-8007720) that prevents Room from being incremental. Consider using JDK 11+ or the embedded JDK shipped with Android Studio 3.5+.
ANTLR Tool version 4.5.3 used for code generation does not …
Run Code Online (Sandbox Code Playgroud) kapt ×10
android ×9
kotlin ×7
android-room ×3
gradle ×3
android-architecture-components ×1
annotations ×1
apt ×1
build ×1
dagger-2 ×1
dagger-hilt ×1
dao ×1
database ×1
java ×1
warnings ×1